v3.0.0-beta.5 (#72)

This commit is contained in:
Daniel Luiz Alves
2025-06-18 18:31:09 -03:00
committed by GitHub
4 changed files with 72 additions and 8 deletions

View File

@@ -4,7 +4,21 @@ import { FastifyReply, FastifyRequest } from "fastify";
import fs from "fs";
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)) {
fs.mkdirSync(uploadsDir, { recursive: true });
}

View File

@@ -9,16 +9,31 @@ import { pipeline } from "stream/promises";
export class FilesystemStorageProvider implements StorageProvider {
private static instance: FilesystemStorageProvider;
private uploadsDir = path.join(process.cwd(), "uploads");
private uploadsDir: string;
private encryptionKey = env.ENCRYPTION_KEY;
private uploadTokens = new Map<string, { objectName: string; expiresAt: number }>();
private downloadTokens = new Map<string, { objectName: string; expiresAt: number; fileName?: string }>();
private constructor() {
this.uploadsDir = this.isDocker() ? "/app/server/uploads" : path.join(process.cwd(), "uploads");
this.ensureUploadsDir();
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 {
if (!FilesystemStorageProvider.instance) {
FilesystemStorageProvider.instance = new FilesystemStorageProvider();

View File

@@ -13,6 +13,7 @@ import { storageRoutes } from "./modules/storage/routes";
import { userRoutes } from "./modules/user/routes";
import fastifyMultipart from "@fastify/multipart";
import fastifyStatic from "@fastify/static";
import * as fsSync from "fs";
import * as fs from "fs/promises";
import crypto from "node:crypto";
import path from "path";
@@ -26,21 +27,36 @@ if (typeof global.crypto === "undefined") {
}
async function ensureDirectories() {
const uploadsDir = path.join(process.cwd(), "uploads");
const tempChunksDir = path.join(process.cwd(), "temp-chunks");
// Use /app/server paths in Docker, current directory for local development
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 {
await fs.access(uploadsDir);
} catch {
await fs.mkdir(uploadsDir, { recursive: true });
console.log("📁 Created uploads directory");
console.log(`📁 Created uploads directory: ${uploadsDir}`);
}
try {
await fs.access(tempChunksDir);
} catch {
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") {
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, {
root: path.join(process.cwd(), "uploads"),
root: uploadsPath,
prefix: "/uploads/",
decorateReply: false,
});

View File

@@ -3,12 +3,15 @@ import { NextRequest, NextResponse } from "next/server";
export async function POST(req: NextRequest, { params }: { params: Promise<{ shareId: string }> }) {
const cookieHeader = req.headers.get("cookie");
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",
headers: {
"Content-Type": "application/json",
cookie: cookieHeader || "",
},
body: body,
redirect: "manual",
});