mirror of
https://github.com/kyantech/Palmr.git
synced 2025-11-02 04:53:26 +00:00
v3.0.0-beta.5 (#72)
This commit is contained in:
@@ -4,7 +4,21 @@ import { FastifyReply, FastifyRequest } from "fastify";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const uploadsDir = path.join(process.cwd(), "uploads/logo");
|
const isDocker = (() => {
|
||||||
|
try {
|
||||||
|
require("fs").statSync("/.dockerenv");
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
return require("fs").readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const baseDir = isDocker ? "/app/server" : process.cwd();
|
||||||
|
const uploadsDir = path.join(baseDir, "uploads/logo");
|
||||||
if (!fs.existsSync(uploadsDir)) {
|
if (!fs.existsSync(uploadsDir)) {
|
||||||
fs.mkdirSync(uploadsDir, { recursive: true });
|
fs.mkdirSync(uploadsDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,31 @@ import { pipeline } from "stream/promises";
|
|||||||
|
|
||||||
export class FilesystemStorageProvider implements StorageProvider {
|
export class FilesystemStorageProvider implements StorageProvider {
|
||||||
private static instance: FilesystemStorageProvider;
|
private static instance: FilesystemStorageProvider;
|
||||||
private uploadsDir = path.join(process.cwd(), "uploads");
|
private uploadsDir: string;
|
||||||
private encryptionKey = env.ENCRYPTION_KEY;
|
private encryptionKey = env.ENCRYPTION_KEY;
|
||||||
private uploadTokens = new Map<string, { objectName: string; expiresAt: number }>();
|
private uploadTokens = new Map<string, { objectName: string; expiresAt: number }>();
|
||||||
private downloadTokens = new Map<string, { objectName: string; expiresAt: number; fileName?: string }>();
|
private downloadTokens = new Map<string, { objectName: string; expiresAt: number; fileName?: string }>();
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
|
this.uploadsDir = this.isDocker() ? "/app/server/uploads" : path.join(process.cwd(), "uploads");
|
||||||
|
|
||||||
this.ensureUploadsDir();
|
this.ensureUploadsDir();
|
||||||
setInterval(() => this.cleanExpiredTokens(), 5 * 60 * 1000);
|
setInterval(() => this.cleanExpiredTokens(), 5 * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isDocker(): boolean {
|
||||||
|
try {
|
||||||
|
fsSync.statSync("/.dockerenv");
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
return fsSync.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static getInstance(): FilesystemStorageProvider {
|
public static getInstance(): FilesystemStorageProvider {
|
||||||
if (!FilesystemStorageProvider.instance) {
|
if (!FilesystemStorageProvider.instance) {
|
||||||
FilesystemStorageProvider.instance = new FilesystemStorageProvider();
|
FilesystemStorageProvider.instance = new FilesystemStorageProvider();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { storageRoutes } from "./modules/storage/routes";
|
|||||||
import { userRoutes } from "./modules/user/routes";
|
import { userRoutes } from "./modules/user/routes";
|
||||||
import fastifyMultipart from "@fastify/multipart";
|
import fastifyMultipart from "@fastify/multipart";
|
||||||
import fastifyStatic from "@fastify/static";
|
import fastifyStatic from "@fastify/static";
|
||||||
|
import * as fsSync from "fs";
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@@ -26,21 +27,36 @@ if (typeof global.crypto === "undefined") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function ensureDirectories() {
|
async function ensureDirectories() {
|
||||||
const uploadsDir = path.join(process.cwd(), "uploads");
|
// Use /app/server paths in Docker, current directory for local development
|
||||||
const tempChunksDir = path.join(process.cwd(), "temp-chunks");
|
const isDocker = (() => {
|
||||||
|
try {
|
||||||
|
fsSync.statSync("/.dockerenv");
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
return fsSync.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const baseDir = isDocker ? "/app/server" : process.cwd();
|
||||||
|
const uploadsDir = path.join(baseDir, "uploads");
|
||||||
|
const tempChunksDir = path.join(baseDir, "temp-chunks");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.access(uploadsDir);
|
await fs.access(uploadsDir);
|
||||||
} catch {
|
} catch {
|
||||||
await fs.mkdir(uploadsDir, { recursive: true });
|
await fs.mkdir(uploadsDir, { recursive: true });
|
||||||
console.log("📁 Created uploads directory");
|
console.log(`📁 Created uploads directory: ${uploadsDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.access(tempChunksDir);
|
await fs.access(tempChunksDir);
|
||||||
} catch {
|
} catch {
|
||||||
await fs.mkdir(tempChunksDir, { recursive: true });
|
await fs.mkdir(tempChunksDir, { recursive: true });
|
||||||
console.log("📁 Created temp-chunks directory");
|
console.log(`📁 Created temp-chunks directory: ${tempChunksDir}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +78,24 @@ async function startServer() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (env.ENABLE_S3 !== "true") {
|
if (env.ENABLE_S3 !== "true") {
|
||||||
|
const isDocker = (() => {
|
||||||
|
try {
|
||||||
|
fsSync.statSync("/.dockerenv");
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
return fsSync.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const baseDir = isDocker ? "/app/server" : process.cwd();
|
||||||
|
const uploadsPath = path.join(baseDir, "uploads");
|
||||||
|
|
||||||
await app.register(fastifyStatic, {
|
await app.register(fastifyStatic, {
|
||||||
root: path.join(process.cwd(), "uploads"),
|
root: uploadsPath,
|
||||||
prefix: "/uploads/",
|
prefix: "/uploads/",
|
||||||
decorateReply: false,
|
decorateReply: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ import { NextRequest, NextResponse } from "next/server";
|
|||||||
export async function POST(req: NextRequest, { params }: { params: Promise<{ shareId: string }> }) {
|
export async function POST(req: NextRequest, { params }: { params: Promise<{ shareId: string }> }) {
|
||||||
const cookieHeader = req.headers.get("cookie");
|
const cookieHeader = req.headers.get("cookie");
|
||||||
const { shareId } = await params;
|
const { shareId } = await params;
|
||||||
|
const body = await req.text();
|
||||||
|
|
||||||
const apiRes = await fetch(`${process.env.API_BASE_URL}/shares/${shareId}/recipients/notify`, {
|
const apiRes = await fetch(`${process.env.API_BASE_URL}/shares/${shareId}/notify`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
cookie: cookieHeader || "",
|
cookie: cookieHeader || "",
|
||||||
},
|
},
|
||||||
|
body: body,
|
||||||
redirect: "manual",
|
redirect: "manual",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user