1
Fork 0
mirror of https://github.com/diced/zipline.git synced 2025-04-11 23:31:17 -05:00

fix: Byte me! >:3

This commit is contained in:
Jayvin Hernandez 2025-02-02 23:18:12 -08:00
parent ee58d26a84
commit eb3bd57e32
No known key found for this signature in database
GPG key ID: 97C2E533F17AF0EB
6 changed files with 6 additions and 8 deletions

View file

@ -3,7 +3,7 @@ import { Readable } from 'stream';
export abstract class Datasource {
public name: string;
public abstract save(file: string, data: Buffer, options?: { type: string; size: number }): Promise<void>;
public abstract save(file: string, data: Buffer, options?: { type: string }): Promise<void>;
public abstract delete(file: string): Promise<void>;
public abstract clear(): Promise<void>;
public abstract size(file: string): Promise<number | null>;

View file

@ -20,12 +20,12 @@ export class S3 extends Datasource {
});
}
public async save(file: string, data: Buffer, options?: { type: string; size: number }): Promise<void> {
public async save(file: string, data: Buffer, options?: { type: string }): Promise<void> {
await this.s3.putObject(
this.config.bucket,
file,
new PassThrough().end(data),
options.size,
data.byteLength,
options ? { 'Content-Type': options.type } : undefined,
);
}

View file

@ -317,12 +317,12 @@ async function handler(req: NextApiReq, res: NextApiRes) {
if (compressionUsed) {
const buffer = await sharp(file.buffer).jpeg({ quality: imageCompressionPercent }).toBuffer();
await datasource.save(fileUpload.name, buffer, { type: 'image/jpeg', size: buffer.byteLength });
await datasource.save(fileUpload.name, buffer, { type: 'image/jpeg' });
logger.info(
`User ${user.username} (${user.id}) compressed image from ${file.buffer.length} -> ${buffer.length} bytes`,
);
} else {
await datasource.save(fileUpload.name, file.buffer, { type: file.mimetype, size: file.size });
await datasource.save(fileUpload.name, file.buffer, { type: file.mimetype });
}
logger.info(`User ${user.username} (${user.id}) uploaded ${fileUpload.name} (${fileUpload.id})`);

View file

@ -57,7 +57,6 @@ async function main() {
fb = await readFile(join(directory, file));
await datasource.save(file, fb, {
type: data[i]?.mimetype ?? 'application/octet-stream',
size: fb.byteLength,
});
}
console.log(`Finished copying files to ${config.datasource.type} storage.`);

View file

@ -150,7 +150,7 @@ async function start() {
},
});
await datasource.save(thumb.name, thumbnail, { type: 'image/jpeg', size: thumbnail.byteLength });
await datasource.save(thumb.name, thumbnail, { type: 'image/jpeg' });
logger.info(`thumbnail saved - ${thumb.name}`);
logger.debug(`thumbnail ${JSON.stringify(thumb)}`);

View file

@ -123,7 +123,6 @@ async function start() {
logger.debug('writing file to datasource');
await datasource.save(file.filename, Buffer.from(fd as Uint8Array), {
type: file.mimetype ?? 'application/octet-stream',
size: file.totalBytes,
});
}