Skip to content

🎥 Make videos programmatically with React

`@remotion/studio-server`: Support fetch()-ing symlinked resources

Jonny Burger8a5c671da5f0
diff --git a/packages/media-parser/src/from-fetch.ts b/packages/media-parser/src/from-fetch.ts
index eac38c9952..6ba3466323 100644
--- a/packages/media-parser/src/from-fetch.ts
+++ b/packages/media-parser/src/from-fetch.ts
@@ -38,6 +38,14 @@ export const fetchReader: ReaderInterface = {
// Disable Next.js caching
cache: 'no-store',
});
+
+ if (
+ res.status.toString().startsWith('4') ||
+ res.status.toString().startsWith('5')
+ ) {
+ throw new Error(`Server returned status code ${res.status} for ${src}`);
+ }
+
if (!res.body) {
throw new Error('No body');
}
diff --git a/packages/studio-server/src/preview-server/serve-static.ts b/packages/studio-server/src/preview-server/serve-static.ts
index 9590f71c6f..eec2907fac 100644
--- a/packages/studio-server/src/preview-server/serve-static.ts
+++ b/packages/studio-server/src/preview-server/serve-static.ts
@@ -17,12 +17,14 @@ export const serveStatic = async function ({
path,
req,
res,
+ allowOutsidePublicFolder,
}: {
root: string;
path: string;
req: IncomingMessage;
res: ServerResponse;
-}) {
+ allowOutsidePublicFolder: boolean;
+}): Promise<void> {
if (req.method !== 'GET' && req.method !== 'HEAD') {
// method not allowed
res.statusCode = 405;
@@ -32,7 +34,7 @@ export const serveStatic = async function ({
return;
}
- if (!RenderInternals.isPathInside(path, root)) {
+ if (!RenderInternals.isPathInside(path, root) && !allowOutsidePublicFolder) {
res.writeHead(500);
res.write('Not allowed to read');
res.end();
@@ -48,6 +50,17 @@ export const serveStatic = async function ({
}
const lstat = await promises.lstat(path);
+ if (lstat.isSymbolicLink()) {
+ const target = await promises.readlink(path);
+ return serveStatic({
+ path: target,
+ root,
+ req,
+ res,
+ allowOutsidePublicFolder: true,
+ });
+ }
+
const isDirectory = lstat.isDirectory();
if (isDirectory) {
diff --git a/packages/studio-server/src/routes.ts b/packages/studio-server/src/routes.ts
index 106daaa618..549eaa7f00 100644
--- a/packages/studio-server/src/routes.ts
+++ b/packages/studio-server/src/routes.ts
@@ -381,6 +381,7 @@ export const handleRoutes = ({
path: filePath,
req: request,
res: response,
+ allowOutsidePublicFolder: false,
});
}
@@ -400,6 +401,7 @@ export const handleRoutes = ({
path: filePath,
req: request,
res: response,
+ allowOutsidePublicFolder: false,
});
}