mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Replace eslint and prettier with Biome
This commit is contained in:
parent
4a5a2ea590
commit
af0d627f19
199 changed files with 16493 additions and 16361 deletions
|
|
@ -1,64 +1,65 @@
|
|||
import type { Config } from "config-manager";
|
||||
import { MediaBackend, MediaBackendType, MediaHasher } from "..";
|
||||
import type { ConvertableMediaFormats } from "../media-converter";
|
||||
import { MediaConverter } from "../media-converter";
|
||||
import { MediaBackend, MediaBackendType, MediaHasher } from "..";
|
||||
import type { ConfigType } from "config-manager";
|
||||
|
||||
export class LocalMediaBackend extends MediaBackend {
|
||||
constructor(config: ConfigType) {
|
||||
super(config, MediaBackendType.LOCAL);
|
||||
}
|
||||
constructor(config: Config) {
|
||||
super(config, MediaBackendType.LOCAL);
|
||||
}
|
||||
|
||||
public async addFile(file: File) {
|
||||
if (this.shouldConvertImages(this.config)) {
|
||||
const fileExtension = file.name.split(".").pop();
|
||||
const mediaConverter = new MediaConverter(
|
||||
fileExtension as ConvertableMediaFormats,
|
||||
this.config.media.conversion
|
||||
.convert_to as ConvertableMediaFormats
|
||||
);
|
||||
file = await mediaConverter.convert(file);
|
||||
}
|
||||
public async addFile(file: File) {
|
||||
let convertedFile = file;
|
||||
if (this.shouldConvertImages(this.config)) {
|
||||
const fileExtension = file.name.split(".").pop();
|
||||
const mediaConverter = new MediaConverter(
|
||||
fileExtension as ConvertableMediaFormats,
|
||||
this.config.media.conversion
|
||||
.convert_to as ConvertableMediaFormats,
|
||||
);
|
||||
convertedFile = await mediaConverter.convert(file);
|
||||
}
|
||||
|
||||
const hash = await new MediaHasher().getMediaHash(file);
|
||||
const hash = await new MediaHasher().getMediaHash(convertedFile);
|
||||
|
||||
const newFile = Bun.file(
|
||||
`${this.config.media.local_uploads_folder}/${hash}`
|
||||
);
|
||||
const newFile = Bun.file(
|
||||
`${this.config.media.local_uploads_folder}/${hash}`,
|
||||
);
|
||||
|
||||
if (await newFile.exists()) {
|
||||
throw new Error("File already exists");
|
||||
}
|
||||
if (await newFile.exists()) {
|
||||
throw new Error("File already exists");
|
||||
}
|
||||
|
||||
await Bun.write(newFile, file);
|
||||
await Bun.write(newFile, convertedFile);
|
||||
|
||||
return {
|
||||
uploadedFile: file,
|
||||
path: `./uploads/${file.name}`,
|
||||
hash: hash,
|
||||
};
|
||||
}
|
||||
return {
|
||||
uploadedFile: convertedFile,
|
||||
path: `./uploads/${convertedFile.name}`,
|
||||
hash: hash,
|
||||
};
|
||||
}
|
||||
|
||||
public async getFileByHash(
|
||||
hash: string,
|
||||
databaseHashFetcher: (sha256: string) => Promise<string | null>
|
||||
): Promise<File | null> {
|
||||
const filename = await databaseHashFetcher(hash);
|
||||
public async getFileByHash(
|
||||
hash: string,
|
||||
databaseHashFetcher: (sha256: string) => Promise<string | null>,
|
||||
): Promise<File | null> {
|
||||
const filename = await databaseHashFetcher(hash);
|
||||
|
||||
if (!filename) return null;
|
||||
if (!filename) return null;
|
||||
|
||||
return this.getFile(filename);
|
||||
}
|
||||
return this.getFile(filename);
|
||||
}
|
||||
|
||||
public async getFile(filename: string): Promise<File | null> {
|
||||
const file = Bun.file(
|
||||
`${this.config.media.local_uploads_folder}/${filename}`
|
||||
);
|
||||
public async getFile(filename: string): Promise<File | null> {
|
||||
const file = Bun.file(
|
||||
`${this.config.media.local_uploads_folder}/${filename}`,
|
||||
);
|
||||
|
||||
if (!(await file.exists())) return null;
|
||||
if (!(await file.exists())) return null;
|
||||
|
||||
return new File([await file.arrayBuffer()], filename, {
|
||||
type: file.type,
|
||||
lastModified: file.lastModified,
|
||||
});
|
||||
}
|
||||
return new File([await file.arrayBuffer()], filename, {
|
||||
type: file.type,
|
||||
lastModified: file.lastModified,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +1,74 @@
|
|||
import { S3Client } from "@jsr/bradenmacdonald__s3-lite-client";
|
||||
import type { Config } from "config-manager";
|
||||
import { MediaBackend, MediaBackendType, MediaHasher } from "..";
|
||||
import type { ConvertableMediaFormats } from "../media-converter";
|
||||
import { MediaConverter } from "../media-converter";
|
||||
import { MediaBackend, MediaBackendType, MediaHasher } from "..";
|
||||
import type { ConfigType } from "config-manager";
|
||||
|
||||
export class S3MediaBackend extends MediaBackend {
|
||||
constructor(
|
||||
config: ConfigType,
|
||||
private s3Client = new S3Client({
|
||||
endPoint: config.s3.endpoint,
|
||||
useSSL: true,
|
||||
region: config.s3.region || "auto",
|
||||
bucket: config.s3.bucket_name,
|
||||
accessKey: config.s3.access_key,
|
||||
secretKey: config.s3.secret_access_key,
|
||||
})
|
||||
) {
|
||||
super(config, MediaBackendType.S3);
|
||||
}
|
||||
constructor(
|
||||
config: Config,
|
||||
private s3Client = new S3Client({
|
||||
endPoint: config.s3.endpoint,
|
||||
useSSL: true,
|
||||
region: config.s3.region || "auto",
|
||||
bucket: config.s3.bucket_name,
|
||||
accessKey: config.s3.access_key,
|
||||
secretKey: config.s3.secret_access_key,
|
||||
}),
|
||||
) {
|
||||
super(config, MediaBackendType.S3);
|
||||
}
|
||||
|
||||
public async addFile(file: File) {
|
||||
if (this.shouldConvertImages(this.config)) {
|
||||
const fileExtension = file.name.split(".").pop();
|
||||
const mediaConverter = new MediaConverter(
|
||||
fileExtension as ConvertableMediaFormats,
|
||||
this.config.media.conversion
|
||||
.convert_to as ConvertableMediaFormats
|
||||
);
|
||||
file = await mediaConverter.convert(file);
|
||||
}
|
||||
public async addFile(file: File) {
|
||||
let convertedFile = file;
|
||||
if (this.shouldConvertImages(this.config)) {
|
||||
const fileExtension = file.name.split(".").pop();
|
||||
const mediaConverter = new MediaConverter(
|
||||
fileExtension as ConvertableMediaFormats,
|
||||
this.config.media.conversion
|
||||
.convert_to as ConvertableMediaFormats,
|
||||
);
|
||||
convertedFile = await mediaConverter.convert(file);
|
||||
}
|
||||
|
||||
const hash = await new MediaHasher().getMediaHash(file);
|
||||
const hash = await new MediaHasher().getMediaHash(convertedFile);
|
||||
|
||||
await this.s3Client.putObject(file.name, file.stream(), {
|
||||
size: file.size,
|
||||
});
|
||||
await this.s3Client.putObject(
|
||||
convertedFile.name,
|
||||
convertedFile.stream(),
|
||||
{
|
||||
size: convertedFile.size,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
uploadedFile: file,
|
||||
hash: hash,
|
||||
};
|
||||
}
|
||||
return {
|
||||
uploadedFile: convertedFile,
|
||||
hash: hash,
|
||||
};
|
||||
}
|
||||
|
||||
public async getFileByHash(
|
||||
hash: string,
|
||||
databaseHashFetcher: (sha256: string) => Promise<string | null>
|
||||
): Promise<File | null> {
|
||||
const filename = await databaseHashFetcher(hash);
|
||||
public async getFileByHash(
|
||||
hash: string,
|
||||
databaseHashFetcher: (sha256: string) => Promise<string | null>,
|
||||
): Promise<File | null> {
|
||||
const filename = await databaseHashFetcher(hash);
|
||||
|
||||
if (!filename) return null;
|
||||
if (!filename) return null;
|
||||
|
||||
return this.getFile(filename);
|
||||
}
|
||||
return this.getFile(filename);
|
||||
}
|
||||
|
||||
public async getFile(filename: string): Promise<File | null> {
|
||||
try {
|
||||
await this.s3Client.statObject(filename);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
public async getFile(filename: string): Promise<File | null> {
|
||||
try {
|
||||
await this.s3Client.statObject(filename);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
const file = await this.s3Client.getObject(filename);
|
||||
const file = await this.s3Client.getObject(filename);
|
||||
|
||||
return new File([await file.arrayBuffer()], filename, {
|
||||
type: file.headers.get("Content-Type") || "undefined",
|
||||
});
|
||||
}
|
||||
return new File([await file.arrayBuffer()], filename, {
|
||||
type: file.headers.get("Content-Type") || "undefined",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue