-
Notifications
You must be signed in to change notification settings - Fork 0
Message Storing and Invite links #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { MigrationMap, Tables, VersionMap } from '../../classes/tables.ts' | ||
| import { Knex } from '../../modules.ts' | ||
|
|
||
| export default class extends Tables { | ||
| override versions(versions: VersionMap) { | ||
| versions.set('message', 0) | ||
|
|
||
| return versions | ||
| } | ||
|
|
||
| override migrations(knex: Knex, migrations: MigrationMap) { | ||
| migrations.set('message', { | ||
| 0: async ()=>{ | ||
| await knex.schema() | ||
| .createTable('_message', (table) => { | ||
| table.increments('id').primary() | ||
| table.integer('user_id').notNullable() | ||
| table.foreign('user_id', 'fk_user_id').references('_root_user.id') | ||
| table.timestamp('created_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP')) | ||
| table.string('content').notNullable() | ||
| }) | ||
| }, | ||
| }) | ||
|
|
||
| return migrations | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| {% extends "extension.html" %} | ||
|
|
||
| {% block head %} | ||
| <link href="/invite/index.css" rel="stylesheet"> | ||
| {% endblock %} | ||
|
|
||
|
|
||
| {% block body %} | ||
| <table id="invite_table"> | ||
| <thead> | ||
| <tr> | ||
| <th>ID</th> | ||
| <th>Link</th> | ||
| <th>Created at</th> | ||
| <th>Used</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for link in invite_links %} | ||
| <tr class={{"used" if link.used else " "}}> | ||
| <td>{{link.id}}</td> | ||
| <td>{{link.link}}</td> | ||
| <td>{{link.created_at}}</td> | ||
| <td>{{"Yes" if link.used else "No"}}</td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| <a href="/invite/create" class="button">Create Invite</a> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { ExtensionBase, Knex } from '../../modules.ts' | ||
| import { unpack } from '../../util.ts' | ||
|
|
||
| export default class extends ExtensionBase { | ||
| override name = 'invite' | ||
| override title = 'Invite' | ||
| override tables = true | ||
| override admin_only = true | ||
|
|
||
| invite_URL = 'http://127.0.0.1:8000/invite/register/' | ||
|
|
||
| override handle: Extension['handle'] = async (ctx) => { | ||
| let [knex]: [Knex] = this.get_dependencies('Knex') | ||
| var location = ctx.path.shift() | ||
|
|
||
| switch (location) { | ||
| case '': | ||
| case undefined:{ | ||
|
|
||
| var [invite_links, err] = await knex | ||
| .query('_invite') | ||
| .select<string[]>('*') | ||
| .then(unpack<string[]>) | ||
|
|
||
| ctx.context.invite_links = invite_links | ||
| return this.return_html(ctx, 'index') | ||
| } | ||
| case 'create': | ||
|
|
||
| const chars = 'abcdefghijklmnopqrstuvwxyz0123456789' | ||
| let random_chars = 'r' | ||
| for (let i = 0; i < 8; i++) { | ||
| random_chars += chars.charAt(Math.floor(Math.random() * chars.length)); | ||
| } | ||
|
|
||
| let invite_link = this.invite_URL + random_chars + Date.now(); | ||
| const time = new Date().toLocaleTimeString('en-US', {hour12: false}); | ||
|
|
||
| await knex.query('_invite') | ||
| // @ts-expect-error | ||
| .insert({link: invite_link, created_at: new Date().toLocaleTimeString('en-US', {hour12: false})}) | ||
|
|
||
| ctx.context.invite_links = invite_links | ||
|
|
||
| return this.return(ctx, undefined, location='/invite') | ||
| default: { | ||
| return this.return_file(ctx, location) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
|
|
||
| table { | ||
| margin: 2%; | ||
| padding-bottom: 5%; | ||
| text-align: center; | ||
| } | ||
|
|
||
| table th, td{ | ||
| border: 1px solid; | ||
| padding: 10px; | ||
| } | ||
|
|
||
| .used{ | ||
| color: #a5a5a5; | ||
| font-style: italic; | ||
| font-weight: lighter; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { MigrationMap, Tables, VersionMap } from '../../classes/tables.ts' | ||
| import { Knex } from '../../modules.ts' | ||
|
|
||
| export default class extends Tables { | ||
| override versions(versions: VersionMap) { | ||
| versions.set('invite', 0) | ||
|
|
||
| return versions | ||
| } | ||
|
|
||
| override migrations(knex: Knex, migrations: MigrationMap) { | ||
| migrations.set('invite', { | ||
| 0: async ()=>{ | ||
| await knex.schema() | ||
| .createTable('_invite', (table) => { | ||
| table.increments('id').primary() | ||
| table.string('link').notNullable() | ||
| table.timestamp('created_at').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP')) | ||
| table.boolean('used').notNullable().defaultTo(false) | ||
| }) | ||
| }, | ||
| }) | ||
|
|
||
| return migrations | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.