fix: accept missing on initial creation

pull/249/head
Sylvie 6 months ago
parent c228a9f6c3
commit 7cd56bc4ed
No known key found for this signature in database
GPG Key ID: 75AB0FE5B983A3AF

@ -131,7 +131,13 @@ export class MySQLDatabase implements Database {
return new Promise(async (resolve, reject) => {
if (!this._ready) return reject(new Error('MySQL not ready'));
if (await this.get(table, key)) reject(new Error(`${table == 'assfiles' ? 'File' : table == 'assusers' ? 'User' : 'Token'} key ${key} already exists`));
try {
if (await this.get(table, key))
reject(new Error(`${table == 'assfiles' ? 'File' : table == 'assusers' ? 'User' : 'Token'} key ${key} already exists`));
} catch (err: any) {
if (!err.message.includes('not found in'))
reject(err);
}
const query = `
INSERT INTO ${table} ( NanoID, Data )
@ -153,7 +159,8 @@ VALUES ('${key}', '${JSON.stringify(data)}');
// Disgustingly interpret the query results
const rows_tableData = (rowz as unknown as { [key: string]: string }[])[0] as unknown as ({ Data: UploadToken | AssFile | AssUser | undefined });
resolve(rows_tableData?.Data ?? undefined);
if (rows_tableData?.Data) resolve(rows_tableData.Data);
else throw new Error(`Key '${key}' not found in '${table}'`);
} catch (err) {
reject(err);
}

Loading…
Cancel
Save