feat: nextcloud sync
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { client } from "$lib/server/nextcloud";
|
||||
import { error } from "@sveltejs/kit";
|
||||
import type { RequestHandler } from "./$types";
|
||||
import mime from "mime-types";
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
const { path } = params;
|
||||
|
||||
if (!path) {
|
||||
throw error(400, "Path is required");
|
||||
}
|
||||
|
||||
try {
|
||||
// Fetch from Nextcloud. We assume the path is relative to the root or a specific folder.
|
||||
// If your files are in a specific folder, e.g., "Schreifuchs", prepend it here.
|
||||
const buffer = await client.getFileContents("/" + path);
|
||||
const contentType = mime.lookup(path) || "application/octet-stream";
|
||||
|
||||
return new Response(buffer as any, {
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": "public, max-age=3600" // Cache for 1 hour
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Error fetching asset from Nextcloud: ${path}`, e);
|
||||
throw error(404, "Asset not found");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user