-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(media): approve loopback video paths when minting URLs #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
webadderall
merged 2 commits into
webadderallorg:main
from
meiiie:fix/local-media-url-approval
Apr 22, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import fs from "node:fs/promises"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| describe("media server path policy", () => { | ||
| let tempRoot: string; | ||
| let appDataPath: string; | ||
| let userDataPath: string; | ||
| let tempPath: string; | ||
| let appPath: string; | ||
|
|
||
| beforeEach(async () => { | ||
| tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "recordly-media-server-")); | ||
| appDataPath = path.join(tempRoot, "AppData"); | ||
| userDataPath = path.join(tempRoot, "UserData"); | ||
| tempPath = path.join(tempRoot, "Temp"); | ||
| appPath = path.join(tempRoot, "App"); | ||
|
|
||
| await Promise.all( | ||
| [appDataPath, userDataPath, tempPath, appPath].map((dirPath) => | ||
| fs.mkdir(dirPath, { recursive: true }), | ||
| ), | ||
| ); | ||
|
|
||
| vi.resetModules(); | ||
| vi.doMock("electron", () => ({ | ||
| app: { | ||
| isPackaged: false, | ||
| getAppPath: () => appPath, | ||
| getPath: (name: string) => { | ||
| if (name === "appData") return appDataPath; | ||
| if (name === "userData") return userDataPath; | ||
| if (name === "temp") return tempPath; | ||
| return tempRoot; | ||
| }, | ||
| setPath: () => undefined, | ||
| }, | ||
| })); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| vi.resetModules(); | ||
| vi.doUnmock("electron"); | ||
| if (tempRoot) { | ||
| await fs.rm(tempRoot, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects existing media files outside the session directories until they are approved", async () => { | ||
| const downloadsPath = path.join(tempRoot, "Downloads"); | ||
| const videoPath = path.join(downloadsPath, "personal-video.mp4"); | ||
| await fs.mkdir(downloadsPath, { recursive: true }); | ||
| await fs.writeFile(videoPath, "test-video"); | ||
|
|
||
| const { isAllowedMediaPath } = await import("./mediaServer"); | ||
| const { rememberApprovedLocalReadPath } = await import("./ipc/project/manager"); | ||
|
|
||
| expect(isAllowedMediaPath(videoPath)).toBe(false); | ||
|
|
||
| await rememberApprovedLocalReadPath(videoPath); | ||
|
|
||
| expect(isAllowedMediaPath(videoPath)).toBe(true); | ||
| }); | ||
|
|
||
| it("rejects missing media files outside the allowed directories", async () => { | ||
| const missingPath = path.join(tempRoot, "Downloads", "missing.mp4"); | ||
| const { isAllowedMediaPath } = await import("./mediaServer"); | ||
|
|
||
| expect(isAllowedMediaPath(missingPath)).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import path from "node:path"; | ||
|
|
||
| export const MEDIA_CONTENT_TYPES: Record<string, string> = { | ||
| ".mp4": "video/mp4", | ||
| ".webm": "video/webm", | ||
| ".mov": "video/quicktime", | ||
| ".mkv": "video/x-matroska", | ||
| ".avi": "video/x-msvideo", | ||
| ".wav": "audio/wav", | ||
| ".mp3": "audio/mpeg", | ||
| ".ogg": "audio/ogg", | ||
| ".png": "image/png", | ||
| ".jpg": "image/jpeg", | ||
| ".jpeg": "image/jpeg", | ||
| }; | ||
|
|
||
| export function getMediaContentType(filePath: string): string { | ||
| return MEDIA_CONTENT_TYPES[path.extname(filePath).toLowerCase()] ?? "application/octet-stream"; | ||
| } | ||
|
|
||
| export function isSupportedLocalMediaPath(filePath: string): boolean { | ||
| return path.extname(filePath).toLowerCase() in MEDIA_CONTENT_TYPES; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.