Lint errors
This commit is contained in:
parent
0c72d5a37c
commit
1d82c4ffb9
6 changed files with 102 additions and 97 deletions
|
|
@ -6,9 +6,9 @@ const db = new Database("./data/mydb.sqlite", { create: true });
|
||||||
|
|
||||||
function getTableInfo(tableName: string) {
|
function getTableInfo(tableName: string) {
|
||||||
try {
|
try {
|
||||||
return db.query(`PRAGMA table_info('${tableName}')`).all() as Array<{ name: string}>;
|
return db.query(`PRAGMA table_info('${tableName}')`).all() as Array<{ name: string }>;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error getting table info for ${tableName}:`, error)
|
console.error(`Error getting table info for ${tableName}:`, error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +64,9 @@ try {
|
||||||
console.log("Added column file_names.storage_key");
|
console.log("Added column file_names.storage_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentVersion = (db.query("PRAGMA user_version").get() as { user_version?: number}).user_version ?? 0;
|
const currentVersion =
|
||||||
|
(db.query("PRAGMA user_version").get() as { user_version?: number }).user_version ?? 0;
|
||||||
|
|
||||||
if (currentVersion < 2) {
|
if (currentVersion < 2) {
|
||||||
db.exec("PRAGMA user_version = 2;");
|
db.exec("PRAGMA user_version = 2;");
|
||||||
console.log(`Updated database to version 2 (was ${currentVersion}).`);
|
console.log(`Updated database to version 2 (was ${currentVersion}).`);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ export const download = new Elysia()
|
||||||
const fileName = sanitize(decodeURIComponent(params.fileName));
|
const fileName = sanitize(decodeURIComponent(params.fileName));
|
||||||
|
|
||||||
const fileRow = db
|
const fileRow = db
|
||||||
.query(`
|
.query(
|
||||||
|
`
|
||||||
SELECT storage_key, file_name
|
SELECT storage_key, file_name
|
||||||
FROM file_names
|
FROM file_names
|
||||||
WHERE job_id = ? AND file_name = ?
|
WHERE job_id = ? AND file_name = ?
|
||||||
|
|
@ -36,7 +37,7 @@ export const download = new Elysia()
|
||||||
}
|
}
|
||||||
|
|
||||||
const storage = getStorage();
|
const storage = getStorage();
|
||||||
const stream = await storage.getStream(fileRow.storage_key!);
|
const stream = storage.getStream(fileRow.storage_key!);
|
||||||
|
|
||||||
return new Response(stream, {
|
return new Response(stream, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -57,7 +58,7 @@ export const download = new Elysia()
|
||||||
.query("SELECT * FROM jobs WHERE user_id = ? AND id = ?")
|
.query("SELECT * FROM jobs WHERE user_id = ? AND id = ?")
|
||||||
.get(user.id, params.jobId);
|
.get(user.id, params.jobId);
|
||||||
|
|
||||||
if(!job) {
|
if (!job) {
|
||||||
return redirect(`${WEBROOT}/results`, 302);
|
return redirect(`${WEBROOT}/results`, 302);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,12 @@ export const upload = new Elysia().use(userService).post(
|
||||||
const buffer = Buffer.from(await file.arrayBuffer());
|
const buffer = Buffer.from(await file.arrayBuffer());
|
||||||
await storage.save(storageKey, buffer);
|
await storage.save(storageKey, buffer);
|
||||||
|
|
||||||
db.query(`
|
db.query(
|
||||||
|
`
|
||||||
INSERT INTO file_names (job_id, file_name, storage_key)
|
INSERT INTO file_names (job_id, file_name, storage_key)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
`).run(jobIdValue, sanitizedFileName, storageKey);
|
`,
|
||||||
|
).run(jobIdValue, sanitizedFileName, storageKey);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (body?.file) {
|
if (body?.file) {
|
||||||
|
|
@ -43,7 +45,7 @@ export const upload = new Elysia().use(userService).post(
|
||||||
await saveFile(file);
|
await saveFile(file);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await saveFile(body.file);;
|
await saveFile(body.file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export class LocalStorageAdapter implements IStorageAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(`Failed to delete file at ${fullPath}: `, error);
|
console.error(`Failed to delete file at ${fullPath}: `, error);
|
||||||
throw error
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,14 +30,14 @@ export class S3StorageAdapter implements IStorageAdapter {
|
||||||
async delete(key: string): Promise<void> {
|
async delete(key: string): Promise<void> {
|
||||||
const file: S3File = s3.file(key, {
|
const file: S3File = s3.file(key, {
|
||||||
bucket: this.bucket,
|
bucket: this.bucket,
|
||||||
})
|
});
|
||||||
|
|
||||||
await file.delete();
|
await file.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
getStream(key: string): ReadableStream<Uint8Array> {
|
getStream(key: string): ReadableStream<Uint8Array> {
|
||||||
const file: S3File = s3.file(key, {
|
const file: S3File = s3.file(key, {
|
||||||
bucket: this.bucket
|
bucket: this.bucket,
|
||||||
});
|
});
|
||||||
return file.stream();
|
return file.stream();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue