🐛 fix #289
This commit is contained in:
parent
c7ed245433
commit
1350f2cbac
@ -1,21 +1,6 @@
|
|||||||
import path from "path";
|
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import fse from "fs-extra";
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
if (!process.env.STORAGE_PROVIDER) process.env.STORAGE_PROVIDER = "file";
|
|
||||||
// TODO:nodejs path.join trailing slash windows compatible
|
|
||||||
if (process.env.STORAGE_PROVIDER === "file") {
|
|
||||||
if (process.env.STORAGE_LOCATION) {
|
|
||||||
if (!process.env.STORAGE_LOCATION.startsWith("/")) {
|
|
||||||
process.env.STORAGE_LOCATION = path.join(__dirname, "..", process.env.STORAGE_LOCATION, "/");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
process.env.STORAGE_LOCATION = path.join(__dirname, "..", "files", "/");
|
|
||||||
}
|
|
||||||
fse.ensureDirSync(process.env.STORAGE_LOCATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
import { CDNServer } from "./Server";
|
import { CDNServer } from "./Server";
|
||||||
const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
|
const server = new CDNServer({ port: Number(process.env.PORT) || 3003 });
|
||||||
server
|
server
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { FileStorage } from "./FileStorage";
|
import { FileStorage } from "./FileStorage";
|
||||||
|
import path from "path";
|
||||||
|
import fse from "fs-extra";
|
||||||
|
process.cwd();
|
||||||
|
|
||||||
export interface Storage {
|
export interface Storage {
|
||||||
set(path: string, data: Buffer): Promise<void>;
|
set(path: string, data: Buffer): Promise<void>;
|
||||||
@ -8,7 +11,17 @@ export interface Storage {
|
|||||||
|
|
||||||
var storage: Storage;
|
var storage: Storage;
|
||||||
|
|
||||||
if (process.env.STORAGE_PROVIDER === "file") {
|
if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
|
||||||
|
var location = process.env.STORAGE_LOCATION;
|
||||||
|
if (location) {
|
||||||
|
location = path.resolve(location);
|
||||||
|
} else {
|
||||||
|
location = path.join(process.cwd(), "files");
|
||||||
|
}
|
||||||
|
console.log(`[CDN] storage location: ${location}`);
|
||||||
|
fse.ensureDirSync(location);
|
||||||
|
process.env.STORAGE_LOCATION = location;
|
||||||
|
|
||||||
storage = new FileStorage();
|
storage = new FileStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user