-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ThreeDify/dev
Dev => Master
- Loading branch information
Showing
36 changed files
with
978 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
19 changes: 19 additions & 0 deletions
19
migrations/20201205154738_alter_reconstructions_table_add_reconstruction_file_column.ts
This file contains 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,19 @@ | ||
import * as Knex from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.table( | ||
'reconstructions', | ||
(table: Knex.AlterTableBuilder) => { | ||
table.string('reconstruction_file').nullable(); | ||
} | ||
); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.table( | ||
'reconstructions', | ||
(table: Knex.AlterTableBuilder) => { | ||
table.dropColumn('reconstruction_file'); | ||
} | ||
); | ||
} |
This file contains 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,16 @@ | ||
import * as Knex from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.createTable('apps', (table: Knex.CreateTableBuilder) => { | ||
table.bigIncrements('id').primary(); | ||
table.string('name').notNullable(); | ||
table.string('domain').notNullable(); | ||
table.string('key', 2000).notNullable().unique(); | ||
table.string('secret', 2000).notNullable(); | ||
table.timestamps(false, true); | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.dropTableIfExists('apps'); | ||
} |
This file contains 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 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,63 @@ | ||
import readline from 'readline'; | ||
import { ValidationResult } from 'joi'; | ||
import Debug, { Debugger } from 'debug'; | ||
|
||
import db from '../src/utils/db'; | ||
import NewApp from '../src/domain/NewApp'; | ||
import appAuth from '../src/services/appAuth'; | ||
import NewAppValidationSchema from '../src/validationSchema/NewAppValidationSchema'; | ||
|
||
const debug: Debugger = Debug('threedify:script:generateApp'); | ||
|
||
async function question( | ||
rl: readline.Interface, | ||
question: string | ||
): Promise<string> { | ||
return new Promise((resolve) => { | ||
rl.question(question, (answer) => resolve(answer)); | ||
}); | ||
} | ||
|
||
(async () => { | ||
const reader = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
try { | ||
debug('Connecting to database...'); | ||
db.init(); | ||
|
||
debug('Enter app details...'); | ||
const newApp: NewApp = { | ||
name: await question(reader, 'App name? '), | ||
domain: await question(reader, 'App domain? '), | ||
}; | ||
reader.close(); | ||
|
||
debug('Validating app details...'); | ||
const result: ValidationResult = NewAppValidationSchema.validate(newApp, { | ||
abortEarly: false, | ||
}); | ||
|
||
if (result.error) { | ||
debug('Validation failed...'); | ||
debug('Validation Errors: %O', result.error.details); | ||
|
||
process.exit(1); | ||
} | ||
|
||
debug('Creating app...'); | ||
const validatedApp: NewApp = result.value; | ||
const app = await appAuth.createNewApp(validatedApp); | ||
|
||
debug('Save the app key and secret...'); | ||
debug('App Key: %s', app?.key); | ||
debug('App Secret: %s', app?.rawSecret); | ||
} catch (err) { | ||
debug('Oops! an error occurred: %O', err); | ||
process.exit(2); | ||
} | ||
|
||
process.exit(0); | ||
})(); |
This file contains 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 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
Oops, something went wrong.