feat: allow full paths (#393)

This commit is contained in:
diced 2023-05-13 00:12:29 -07:00
parent a7ad58b196
commit ec09458ad3
No known key found for this signature in database
GPG key ID: 370BD1BA142842D1
3 changed files with 8 additions and 9 deletions

View file

@ -4,7 +4,7 @@ import { inspect } from 'util';
import Logger from 'lib/logger';
import { humanToBytes } from 'utils/bytes';
import { tmpdir } from 'os';
import { join } from 'path';
import { join, resolve } from 'path';
const discord_content = s
.object({
@ -53,7 +53,7 @@ const validator = s.object({
type: s.enum('local', 's3', 'supabase').default('local'),
local: s
.object({
directory: s.string.default('./uploads'),
directory: s.string.default(resolve('./uploads')).transform((v) => resolve(v)),
})
.default({
directory: './uploads',

View file

@ -11,23 +11,23 @@ export class Local extends Datasource {
}
public async save(file: string, data: Buffer): Promise<void> {
await writeFile(join(process.cwd(), this.path, file), data);
await writeFile(join(this.path, file), data);
}
public async delete(file: string): Promise<void> {
await rm(join(process.cwd(), this.path, file));
await rm(join(this.path, file));
}
public async clear(): Promise<void> {
const files = await readdir(join(process.cwd(), this.path));
const files = await readdir(this.path);
for (let i = 0; i !== files.length; ++i) {
await rm(join(process.cwd(), this.path, files[i]));
await rm(join(this.path, files[i]));
}
}
public get(file: string): ReadStream {
const full = join(process.cwd(), this.path, file);
const full = join(this.path, file);
if (!existsSync(full)) return null;
try {
@ -38,7 +38,7 @@ export class Local extends Datasource {
}
public async size(file: string): Promise<number> {
const full = join(process.cwd(), this.path, file);
const full = join(this.path, file);
if (!existsSync(full)) return 0;
const stats = await stat(full);

View file

@ -84,7 +84,6 @@ async function start() {
if (config.datasource.type === 'local') {
fd = await open(
join(
process.cwd(),
config.datasource.local.directory,
`${fileName}${compressionUsed ? '.jpg' : `${ext ? '.' : ''}${ext}`}`
),