Skip to content

Modern Docker Management, Designed for Everyone

feat(workspaces): allow uploading non-UTF-8 files to workspaces (#3859)

Neurekaa38a0a2fbff0
diff --git a/backend/pkg/projects/workspace.go b/backend/pkg/projects/workspace.go
index d5d55c977..40a62d096 100644
--- a/backend/pkg/projects/workspace.go
+++ b/backend/pkg/projects/workspace.go
@@ -331,7 +331,7 @@ func createProjectWorkspaceFileInternal(root *os.Root, protected map[string]bool
if err := ensureWritableProjectRelPathInternal(protected, rel); err != nil {
return err
}
- if err := workspacepkg.ValidateTextContent(content, maxFileSizeBytes); err != nil {
+ if err := workspacepkg.ValidateContentSize(content, maxFileSizeBytes); err != nil {
return err
}
if err := ensureProjectPathHasNoSymlinkInternal(root, path.Dir(rel)); err != nil {
@@ -384,7 +384,7 @@ func updateProjectWorkspaceFileInternal(root *os.Root, protected map[string]bool
if err := ensureWritableProjectRelPathInternal(protected, rel); err != nil {
return err
}
- if err := workspacepkg.ValidateTextContent(content, maxFileSizeBytes); err != nil {
+ if err := workspacepkg.ValidateContentSize(content, maxFileSizeBytes); err != nil {
return err
}
if err := ensureProjectPathHasNoSymlinkInternal(root, rel); err != nil {
diff --git a/backend/pkg/projects/workspace_test.go b/backend/pkg/projects/workspace_test.go
index 3edac4ae8..a687fb724 100644
--- a/backend/pkg/projects/workspace_test.go
+++ b/backend/pkg/projects/workspace_test.go
@@ -120,15 +120,6 @@ func TestApplyWorkspaceFileChanges_RejectsUnsafePathsAndProtectedFiles(t *testin
},
upload: []byte("bad\n"),
},
- {
- name: "binary content",
- change: project.WorkspaceFileChange{
- Operation: "create_file",
- RelativePath: "binary.txt",
- UploadIndex: new(0),
- },
- upload: []byte{0},
- },
}
for _, tc := range testCases {
@@ -143,6 +134,23 @@ func TestApplyWorkspaceFileChanges_RejectsUnsafePathsAndProtectedFiles(t *testin
}
}
+func TestApplyWorkspaceFileChanges_CreatesBinaryFileVerbatim(t *testing.T) {
+ t.Parallel()
+
+ projectDir := t.TempDir()
+ require.NoError(t, os.WriteFile(filepath.Join(projectDir, "compose.yaml"), []byte("services: {}\n"), 0o644))
+
+ binary := []byte{0x1f, 0x8b, 0x08, 0x00, 0xff, 0x00, 0xde, 0xad, 0xbe, 0xef}
+ err := ApplyProjectWorkspaceChanges(projectDir, []project.WorkspaceFileChange{
+ {Operation: "create_file", RelativePath: "db.sqlite", UploadIndex: new(0)},
+ }, map[int][]byte{0: binary}, ProjectWorkspaceApplyOptions{ComposeFileName: "compose.yaml"})
+ require.NoError(t, err)
+
+ stored, err := os.ReadFile(filepath.Join(projectDir, "db.sqlite"))
+ require.NoError(t, err)
+ require.Equal(t, binary, stored)
+}
+
func TestApplyWorkspaceFileChanges_WrapsForbiddenSentinelErrors(t *testing.T) {
t.Parallel()
diff --git a/backend/pkg/utils/handlerutil/handlerutil.go b/backend/pkg/utils/handlerutil/handlerutil.go
index fccb8c616..6dd5e580a 100644
--- a/backend/pkg/utils/handlerutil/handlerutil.go
+++ b/backend/pkg/utils/handlerutil/handlerutil.go
@@ -15,7 +15,6 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/middleware"
"github.com/getarcaneapp/arcane/backend/v2/pkg/pagination"
"github.com/getarcaneapp/arcane/backend/v2/pkg/utils/mapper"
- workspacepkg "github.com/getarcaneapp/arcane/backend/v2/pkg/workspace"
"github.com/getarcaneapp/arcane/types/v2/auth"
"github.com/getarcaneapp/arcane/types/v2/base"
)
@@ -132,9 +131,6 @@ func ReadWorkspaceUploads(form multipart.Form, maxFileSizeBytes int64) (map[int]
if int64(len(content)) > maxFileSizeBytes {
return nil, huma.Error413RequestEntityTooLarge(limitMessage)
}
- if err := workspacepkg.ValidateTextContent(content, maxFileSizeBytes); err != nil {
- return nil, huma.Error400BadRequest(err.Error())
- }
uploads[index] = content
}
return uploads, nil
diff --git a/backend/pkg/utils/handlerutil/workspace_test.go b/backend/pkg/utils/handlerutil/workspace_test.go
index 8d071e978..63ec595bf 100644
--- a/backend/pkg/utils/handlerutil/workspace_test.go
+++ b/backend/pkg/utils/handlerutil/workspace_test.go
@@ -77,23 +77,28 @@ func TestReadWorkspaceUploadsInternal(t *testing.T) {
require.Equal(t, []byte("two"), uploads[1])
}
-func TestReadWorkspaceUploadsInternalRejectsInvalidTextAndConfiguredLimit(t *testing.T) {
+func TestReadWorkspaceUploadsInternalAcceptsAnyContentAndEnforcesLimit(t *testing.T) {
tests := []struct {
name string
content []byte
maxBytes int64
status int
}{
- {name: "invalid UTF-8", content: []byte{0xff}, maxBytes: 16, status: http.StatusBadRequest},
- {name: "NUL byte", content: []byte{'a', 0, 'b'}, maxBytes: 16, status: http.StatusBadRequest},
+ {name: "invalid UTF-8", content: []byte{0xff}, maxBytes: 16},
+ {name: "NUL byte", content: []byte{'a', 0, 'b'}, maxBytes: 16},
{name: "configured size", content: []byte("four"), maxBytes: 3, status: http.StatusRequestEntityTooLarge},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- form := workspaceMultipartFormInternal(t, nil, []workspaceUploadFixtureInternal{{name: "upload.txt", content: tt.content}})
- _, err := ReadWorkspaceUploads(form, tt.maxBytes)
- requireWorkspaceHTTPStatusInternal(t, err, tt.status)
+ form := workspaceMultipartFormInternal(t, nil, []workspaceUploadFixtureInternal{{name: "upload.bin", content: tt.content}})
+ uploads, err := ReadWorkspaceUploads(form, tt.maxBytes)
+ if tt.status != 0 {
+ requireWorkspaceHTTPStatusInternal(t, err, tt.status)
+ return
+ }
+ require.NoError(t, err)
+ require.Equal(t, tt.content, uploads[0])
})
}
}
diff --git a/backend/pkg/workspace/workspace.go b/backend/pkg/workspace/workspace.go
index 4ae35b4d6..a9801d6d8 100644
--- a/backend/pkg/workspace/workspace.go
+++ b/backend/pkg/workspace/workspace.go
@@ -37,21 +37,17 @@ func ValidateUpdateManifest(fileTreeRevision string, fileChangeCount, maxFileCha
return nil
}
-func ValidateTextContent(content []byte, maxBytes int64) error {
+// ValidateContentSize enforces the per-file workspace upload limit. Content
+// may be any bytes: text and binary files are both allowed.
+func ValidateContentSize(content []byte, maxBytes int64) error {
if int64(len(content)) > maxBytes {
return errors.Errorf("file exceeds %d MiB limit", maxBytes/(1024*1024))
}
- if !utf8.Valid(content) {
- return errors.New("file must contain valid UTF-8 text")
- }
- if bytes.IndexByte(content, 0) >= 0 {
- return errors.New("file must not contain NUL bytes")
- }
return nil
}
func IsTextContent(content []byte) bool {
- return ValidateTextContent(content, int64(len(content))) == nil
+ return utf8.Valid(content) && bytes.IndexByte(content, 0) < 0
}
func ValidateUploadIndices(changes []UploadReference, uploadCount int, createFileOperation, updateFileOperation string) error {
diff --git a/backend/pkg/workspace/workspace_test.go b/backend/pkg/workspace/workspace_test.go
index 162f78fa2..6d8b47c14 100644
--- a/backend/pkg/workspace/workspace_test.go
+++ b/backend/pkg/workspace/workspace_test.go
@@ -14,12 +14,12 @@ func TestEffectiveMaxFileSizeMB(t *testing.T) {
require.Equal(t, int64(24*1024*1024), MaxFileSizeBytes(24))
}
-func TestValidateTextContent(t *testing.T) {
+func TestValidateContentSize(t *testing.T) {
limit := int64(4)
- require.NoError(t, ValidateTextContent([]byte("text"), limit))
- require.ErrorContains(t, ValidateTextContent([]byte("large"), limit), "file exceeds")
- require.ErrorContains(t, ValidateTextContent([]byte{0xff}, limit), "UTF-8")
- require.ErrorContains(t, ValidateTextContent([]byte{'a', 0}, limit), "NUL")
+ require.NoError(t, ValidateContentSize([]byte("text"), limit))
+ // Any bytes are allowed: binary content is valid as long as it fits.
+ require.NoError(t, ValidateContentSize([]byte{0xff, 0, 0x1f}, limit))
+ require.ErrorContains(t, ValidateContentSize([]byte("large"), limit), "file exceeds")
}
func TestIsTextContent(t *testing.T) {
@@ -28,9 +28,9 @@ func TestIsTextContent(t *testing.T) {
require.False(t, IsTextContent([]byte("hello\x00world")))
}
-func TestValidateTextContentUsesDynamicMiBLimit(t *testing.T) {
+func TestValidateContentSizeUsesDynamicMiBLimit(t *testing.T) {
limit := int64(2 * 1024 * 1024)
- err := ValidateTextContent([]byte(strings.Repeat("a", int(limit+1))), limit)
+ err := ValidateContentSize([]byte(strings.Repeat("a", int(limit+1))), limit)
require.ErrorContains(t, err, "2 MiB")
}
diff --git a/frontend/src/lib/components/workspace-editor/workspace-draft-state.svelte.ts b/frontend/src/lib/components/workspace-editor/workspace-draft-state.svelte.ts
index d5e187c3d..d1cd8bc17 100644
--- a/frontend/src/lib/components/workspace-editor/workspace-draft-state.svelte.ts
+++ b/frontend/src/lib/components/workspace-editor/workspace-draft-state.svelte.ts
@@ -2,7 +2,7 @@ import type { WorkspaceFileDraft } from '#lib/types/workspace';
import { m } from '#lib/paraglide/messages';
import {
isWorkspaceFileSelectionUnder,
- readWorkspaceTextUpload,
+ readWorkspaceUpload,
remapSelectedWorkspaceFileKey,
remapWorkspaceFilePath,
remapWorkspaceFileRecord,
@@ -22,6 +22,7 @@ type WorkspaceDraftStateOptions = {
initialOpenTabs?: string[];
initialSelection?: string;
pendingEntries?: boolean;
+ allowBinary?: boolean;
fallbackTab: string;
isFixedTab: (key: string) => boolean;
isTabAvailable?: (key: string) => boolean;
@@ -38,6 +39,9 @@ type WorkspaceDraftStateOptions = {
export class WorkspaceDraftState {
files = $state<WorkspaceFileDraft[]>([]);
contents = $state<Record<string, string>>({});
+ stagedFiles = $state<Record<string, File>>({});
+ binaryFiles = $state<Record<string, boolean>>({});
+ uploadedText = $state<Record<string, string>>({});
hasErrors = $state<Record<string, boolean>>({});
validationReady = $state<Record<string, boolean>>({});
openTabs = $state<string[]>([]);
@@ -45,6 +49,7 @@ export class WorkspaceDraftState {
readonly #fallbackTab: string;
readonly #pendingEntries: boolean;
+ readonly #allowBinary: boolean;
readonly #isFixedTab: (key: string) => boolean;
readonly #isTabAvailable: (key: string) => boolean;
readonly #planCreate: WorkspaceDraftStateOptions['planCreate'];
@@ -60,6 +65,7 @@ export class WorkspaceDraftState {
this.selectedKey = options.initialSelection ?? options.fallbackTab;
this.#fallbackTab = options.fallbackTab;
this.#pendingEntries = options.pendingEntries ?? true;
+ this.#allowBinary = options.allowBinary ?? true;
this.#isFixedTab = options.isFixedTab;
this.#isTabAvailable = options.isTabAvailable ?? (() => true);
this.#planCreate = options.planCreate;
@@ -68,15 +74,22 @@ export class WorkspaceDraftState {
}
get entries(): WorkspaceDisplayEntry[] {
- return this.files.map((file) => ({
- path: file.relativePath,
- relativePath: file.relativePath,
- name: workspaceFileBasename(file.relativePath),
- isDirectory: !!file.isDirectory,
- size: file.isDirectory ? 0 : (this.contents[file.relativePath]?.length ?? 0),
- content: file.isDirectory ? undefined : (this.contents[file.relativePath] ?? ''),
- pending: this.#pendingEntries
- }));
+ return this.files.map((file) => {
+ const staged = this.stagedFiles[file.relativePath];
+ const binary = this.binaryFiles[file.relativePath] === true;
+ return {
+ path: file.relativePath,
+ relativePath: file.relativePath,
+ name: workspaceFileBasename(file.relativePath),
+ isDirectory: !!file.isDirectory,
+ size: file.isDirectory ? 0 : binary ? (staged?.size ?? 0) : (this.contents[file.relativePath]?.length ?? 0),
+ content: file.isDirectory ? undefined : binary ? undefined : (this.contents[file.relativePath] ?? ''),
+ mimeType: file.isDirectory ? undefined : (staged?.type ?? undefined),
+ editable: binary ? false : undefined,
+ readOnlyReason: binary ? 'binary' : undefined,
+ pending: this.#pendingEntries
+ };
+ });
}
get paths(): ReadonlySet<string> {
@@ -141,9 +154,22 @@ export class WorkspaceDraftState {
uploadFile = async (parentPath: string, files: File[], maxFileSizeMb: number): Promise<string | void> => {
const file = files[0];
if (!file) return m.workspace_upload_file_required();
- const result = await readWorkspaceTextUpload(file, maxFileSizeMb);
+ const result = await readWorkspaceUpload(file, maxFileSizeMb);
if (result.error) return result.error;
- this.createFile(parentPath, file.name, result.content ?? '');
+ const isBinary = result.binary === true;
+ if (isBinary && !this.#allowBinary) return m.workspace_upload_text_required();
+ const relativePath = this.#planCreate(this.paths, parentPath, file.name);
+ if (!relativePath) return;
+ this.files = [...this.files, { relativePath, isDirectory: false }];
+ this.stagedFiles = { ...this.stagedFiles, [relativePath]: file };
+ if (isBinary) {
+ this.binaryFiles = { ...this.binaryFiles, [relativePath]: true };
+ } else {
+ const content = result.content ?? '';
+ this.contents = { ...this.contents, [relativePath]: content };
+ this.uploadedText = { ...this.uploadedText, [relativePath]: content };
+ }
+ this.openTab(`file:${relativePath}`);
};
rename = (relativePath: string, newName: string): string | null => {
@@ -164,6 +190,9 @@ export class WorkspaceDraftState {
remove = (relativePath: string) => {
this.files = this.files.filter((file) => !workspaceFilePathMatches(file.relativePath, relativePath));
this.contents = removeWorkspaceFileRecord(this.contents, relativePath);
+ this.stagedFiles = removeWorkspaceFileRecord(this.stagedFiles, relativePath);
+ this.binaryFiles = removeWorkspaceFileRecord(this.binaryFiles, relativePath);
+ this.uploadedText = removeWorkspaceFileRecord(this.uploadedText, relativePath);
this.hasErrors = removeWorkspaceFileRecord(this.hasErrors, relativePath);
this.validationReady = removeWorkspaceFileRecord(this.validationReady, relativePath);
this.openTabs = this.openTabs.filter((tab) => !isWorkspaceFileSelectionUnder(tab, relativePath));
@@ -173,11 +202,19 @@ export class WorkspaceDraftState {
};
toDrafts(): WorkspaceFileDraft[] {
- return this.files.map((file) => ({
- relativePath: file.relativePath,
- isDirectory: !!file.isDirectory,
- content: file.isDirectory ? undefined : (this.contents[file.relativePath] ?? '')
- }));
+ return this.files.map((file) => {
+ const relativePath = file.relativePath;
+ const staged = this.stagedFiles[relativePath];
+ const binary = this.binaryFiles[relativePath] === true;
+ const uploadedText = this.uploadedText[relativePath];
+ const untouched = uploadedText !== undefined && this.contents[relativePath] === uploadedText;
+ return {
+ relativePath,
+ isDirectory: !!file.isDirectory,
+ content: file.isDirectory ? undefined : binary ? undefined : (this.contents[relativePath] ?? ''),
+ file: file.isDirectory ? undefined : binary || untouched ? staged : undefined
+ };
+ });
}
private ensureValidationState(relativePath: string) {
@@ -195,6 +232,9 @@ export class WorkspaceDraftState {
relativePath: remapWorkspaceFilePath(file.relativePath, oldPath, newPath)
}));
this.contents = remapWorkspaceFileRecord(this.contents, oldPath, newPath);
+ this.stagedFiles = remapWorkspaceFileRecord(this.stagedFiles, oldPath, newPath);
+ this.binaryFiles = remapWorkspaceFileRecord(this.binaryFiles, oldPath, newPath);
+ this.uploadedText = remapWorkspaceFileRecord(this.uploadedText, oldPath, newPath);
this.hasErrors = remapWorkspaceFileRecord(this.hasErrors, oldPath, newPath);
this.validationReady = remapWorkspaceFileRecord(this.validationReady, oldPath, newPath);
this.openTabs = this.openTabs.map((tab) => remapSelectedWorkspaceFileKey(tab, oldPath, newPath) ?? tab);
diff --git a/frontend/src/lib/services/project-service.ts b/frontend/src/lib/services/project-service.ts
index 19ed2a745..bc2120a5d 100644
--- a/frontend/src/lib/services/project-service.ts
+++ b/frontend/src/lib/services/project-service.ts
@@ -69,7 +69,7 @@ class ProjectService extends BaseAPIService {
const fileChanges = workspaceFiles.map((file) => {
if (file.isDirectory) return { operation: 'create_folder' as const, relativePath: file.relativePath };
const uploadIndex = uploads.length;
- uploads.push(new File([file.content ?? ''], file.relativePath));
+ uploads.push(file.file ?? new File([file.content ?? ''], file.relativePath));
return { operation: 'create_file' as const, relativePath: file.relativePath, uploadIndex };
});
form.append(
diff --git a/frontend/src/lib/types/workspace.ts b/frontend/src/lib/types/workspace.ts
index e19ca4973..5873b62b7 100644
--- a/frontend/src/lib/types/workspace.ts
+++ b/frontend/src/lib/types/workspace.ts
@@ -48,4 +48,5 @@ export interface WorkspaceFileDraft {
relativePath: string;
isDirectory?: boolean;
content?: string;
+ file?: File;
}
diff --git a/frontend/src/lib/utils/workspace-files.ts b/frontend/src/lib/utils/workspace-files.ts
index cbfaed058..7c9f8478a 100644
--- a/frontend/src/lib/utils/workspace-files.ts
+++ b/frontend/src/lib/utils/workspace-files.ts
@@ -26,7 +26,9 @@ type WorkspaceDisplayFileChange = Omit<WorkspaceFileChangeDto, 'operation'> & {
export function buildWorkspaceMultipartUpdate<T extends WorkspaceDisplayFileChange>(
draftChanges: T[],
fileContents: Record<string, string>,
- loadedFileContents: Record<string, string>
+ loadedFileContents: Record<string, string>,
+ stagedFiles: Record<string, File> = {},
+ stagedUploadedText: Record<string, string> = {}
): { fileChanges: T[]; files: File[] } {
const fileChanges = draftChanges.map(
({ uploadIndex: _uploadIndex, baselineIndex: _baselineIndex, ...change }) => ({ ...change }) as T
@@ -41,8 +43,33 @@ export function buildWorkspaceMultipartUpdate<T extends WorkspaceDisplayFileChan
files.push(new File([content], workspaceFileBasename(change.relativePath), { type: 'text/plain' }));
};
+ // Stage the picked file verbatim while its content is untouched, so any
+ // file — including binary — is stored byte-for-byte as uploaded. Text
+ // uploads are compared against their own decoded bytes; a staged binary
+ // replacement is always authoritative.
+ const stageStagedFile = (change: T): boolean => {
+ const staged = stagedFiles[change.relativePath];
+ if (!staged) return false;
+ const uploaded = stagedUploadedText[change.relativePath];
+ if (uploaded !== undefined) {
+ const current = fileContents[change.relativePath];
+ if (current !== undefined && current !== uploaded) return false;
+ }
+ change.uploadIndex = files.length;
+ files.push(staged);
+ return true;
+ };
+
+ for (const change of fileChanges) {
+ if ((change.operation === 'create_file' || change.operation === 'update_file') && change.uploadIndex === undefined) {
+ stageStagedFile(change);
+ }
+ }
+
for (const change of fileChanges) {
- if (change.operation === 'create_file') stageText(change, fileContents[change.relativePath] ?? '');
+ if (change.operation === 'create_file' && change.uploadIndex === undefined) {
+ stageText(change, fileContents[change.relativePath] ?? '');
+ }
}
for (const relativePath of changedPaths) {
@@ -63,6 +90,10 @@ export function buildWorkspaceMultipartUpdate<T extends WorkspaceDisplayFileChan
if (change.uploadIndex === undefined) stageText(change, fileContents[relativePath] ?? '');
}
+ for (const change of fileChanges) {
+ if (change.operation === 'update_file' && change.uploadIndex === undefined) stageStagedFile(change);
+ }
+
// Every update also carries the content the draft was based on, so the
// backend can reject a save that would overwrite a concurrent external
// edit to the same file.
@@ -156,14 +187,17 @@ export function planWorkspaceFileMove(
return newPath;
}
-export async function readWorkspaceTextUpload(file: File, maxFileSizeMb: number): Promise<{ content?: string; error?: string }> {
- if (file.size > maxFileSizeMb * 1024 * 1024) return { error: m.workspace_upload_too_large({ maxFileSizeMb }) };
+export async function readWorkspaceUpload(
+ file: File,
+ maxFileSizeMb: number
+): Promise<{ content?: string; binary: boolean; error?: string }> {
+ if (file.size > maxFileSizeMb * 1024 * 1024) return { binary: false, error: m.workspace_upload_too_large({ maxFileSizeMb }) };
try {
const bytes = new Uint8Array(await file.arrayBuffer());
- if (bytes.includes(0)) return { error: m.workspace_upload_text_required() };
- return { content: new TextDecoder('utf-8', { fatal: true }).decode(bytes) };
+ if (bytes.includes(0)) return { binary: true };
+ return { binary: false, content: new TextDecoder('utf-8', { fatal: true }).decode(bytes) };
} catch {
- return { error: m.workspace_upload_text_required() };
+ return { binary: true };
}
}
diff --git a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
index 4ec54d3f2..662264c19 100644
--- a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
+++ b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
@@ -80,7 +80,7 @@
remapWorkspaceFileRecord,
remapSelectedWorkspaceFileKey,
removeWorkspaceFileRecord,
- readWorkspaceTextUpload,
+ readWorkspaceUpload,
workspaceReadOnlyMessage,
type WorkspaceDisplayEntry
} from '#lib/utils/workspace-files';
@@ -119,6 +119,8 @@
let projectWorkspaceLoadErrors = $state<Record<string, string>>({});
let projectWorkspaceLoading = $state<Record<string, boolean>>({});
let projectWorkspaceFileMetadata = $state<Record<string, ProjectWorkspaceFileContent>>({});
+ let projectWorkspaceStagedFiles = $state<Record<string, File>>({});
+ let projectWorkspaceStagedUploadedText = $state<Record<string, string>>({});
let projectWorkspaceFilePromises: Record<string, Promise<IncludeFile | ProjectWorkspaceFileContent> | undefined> = {};
const globalVariableMap = $derived(globalVariablesToMap(data.globalVariables));
const projectWorkspaceMaxFileSizeMb = $derived($settingsStore?.projectWorkspaceMaxFileSizeMb ?? 10);
@@ -743,7 +745,9 @@
const workspaceUpdate = buildWorkspaceMultipartUpdate(
projectWorkspaceChanges,
{ ...projectWorkspaceContents, ...includeFilesState },
- { ...loadedProjectWorkspaceContents, ...loadedIncludeFileContents }
+ { ...loadedProjectWorkspaceContents, ...loadedIncludeFileContents },
+ projectWorkspaceStagedFiles,
+ projectWorkspaceStagedUploadedText
);
let workspaceCommitted = false;
isLoading.saving = true;
@@ -772,6 +776,8 @@
)
};
projectWorkspaceChanges = [];
+ projectWorkspaceStagedFiles = {};
+ projectWorkspaceStagedUploadedText = {};
}
const updatedProject = await projectService.updateProject(
@@ -1148,6 +1154,8 @@
projectWorkspaceLoadErrors = remapWorkspaceFileRecord(projectWorkspaceLoadErrors, oldPath, newPath);
projectWorkspaceLoading = remapWorkspaceFileRecord(projectWorkspaceLoading, oldPath, newPath);
projectWorkspaceFileMetadata = remapWorkspaceFileRecord(projectWorkspaceFileMetadata, oldPath, newPath);
+ projectWorkspaceStagedFiles = remapWorkspaceFileRecord(projectWorkspaceStagedFiles, oldPath, newPath);
+ projectWorkspaceStagedUploadedText = remapWorkspaceFileRecord(projectWorkspaceStagedUploadedText, oldPath, newPath);
includeFilesState = remapWorkspaceFileRecord(includeFilesState, oldPath, newPath);
loadedIncludeFileContents = remapWorkspaceFileRecord(loadedIncludeFileContents, oldPath, newPath);
includeFilesPanelStates = remapWorkspaceFileRecord(includeFilesPanelStates, oldPath, newPath);
@@ -1168,6 +1176,8 @@
projectWorkspaceLoadErrors = removeWorkspaceFileRecord(projectWorkspaceLoadErrors, relativePath);
projectWorkspaceLoading = removeWorkspaceFileRecord(projectWorkspaceLoading, relativePath);
projectWorkspaceFileMetadata = removeWorkspaceFileRecord(projectWorkspaceFileMetadata, relativePath);
+ projectWorkspaceStagedFiles = removeWorkspaceFileRecord(projectWorkspaceStagedFiles, relativePath);
+ projectWorkspaceStagedUploadedText = removeWorkspaceFileRecord(projectWorkspaceStagedUploadedText, relativePath);
includeFilesState = removeWorkspaceFileRecord(includeFilesState, relativePath);
loadedIncludeFileContents = removeWorkspaceFileRecord(loadedIncludeFileContents, relativePath);
includeFilesPanelStates = removeWorkspaceFileRecord(includeFilesPanelStates, relativePath);
@@ -1179,12 +1189,16 @@
}
}
- function createProjectWorkspaceFile(parentPath: string, name: string, content = '') {
+ function createProjectWorkspaceFile(parentPath: string, name: string, content = '', stagedFile?: File) {
const relativePath = planProjectWorkspaceFileCreate(projectWorkspacePaths, parentPath, name, composeFileName);
if (!relativePath) return;
projectWorkspaceChanges = [...projectWorkspaceChanges, { operation: 'create_file', relativePath }];
projectWorkspaceContents = { ...projectWorkspaceContents, [relativePath]: content };
loadedProjectWorkspaceContents = { ...loadedProjectWorkspaceContents, [relativePath]: content };
+ if (stagedFile) {
+ projectWorkspaceStagedFiles = { ...projectWorkspaceStagedFiles, [relativePath]: stagedFile };
+ projectWorkspaceStagedUploadedText = { ...projectWorkspaceStagedUploadedText, [relativePath]: content };
+ }
projectWorkspaceFileMetadata = {
...projectWorkspaceFileMetadata,
[relativePath]: {
@@ -1192,7 +1206,7 @@
relativePath,
name: workspaceFileBasename(relativePath),
size: content.length,
- mimeType: 'text/plain',
+ mimeType: stagedFile?.type || 'text/plain',
content,
editable: true
}
@@ -1205,9 +1219,30 @@
async function uploadProjectWorkspaceFiles(parentPath: string, files: File[]): Promise<string | void> {
const file = files[0];
if (!file) return m.workspace_upload_file_required();
- const result = await readWorkspaceTextUpload(file, projectWorkspaceMaxFileSizeMb);
+ const result = await readWorkspaceUpload(file, projectWorkspaceMaxFileSizeMb);
if (result.error) return result.error;
- createProjectWorkspaceFile(parentPath, file.name, result.content ?? '');
+ if (result.binary) {
+ const relativePath = planProjectWorkspaceFileCreate(projectWorkspacePaths, parentPath, file.name, composeFileName);
+ if (!relativePath) return;
+ projectWorkspaceChanges = [...projectWorkspaceChanges, { operation: 'create_file', relativePath }];
+ projectWorkspaceStagedFiles = { ...projectWorkspaceStagedFiles, [relativePath]: file };
+ projectWorkspaceFileMetadata = {
+ ...projectWorkspaceFileMetadata,
+ [relativePath]: {
+ path: relativePath,
+ relativePath,
+ name: file.name,
+ size: file.size,
+ mimeType: file.type || 'application/octet-stream',
+ editable: false,
+ readOnlyReason: 'binary'
+ }
+ };
+ projectWorkspaceLoadErrors = removeWorkspaceFileRecord(projectWorkspaceLoadErrors, relativePath);
+ openFileTab(`file:${relativePath}`);
+ return;
+ }
+ createProjectWorkspaceFile(parentPath, file.name, result.content ?? '', file);
}
async function downloadProjectWorkspaceFile(relativePath: string) {
diff --git a/frontend/src/routes/(app)/projects/new/+page.svelte b/frontend/src/routes/(app)/projects/new/+page.svelte
index c089d80b2..c09200e10 100644
--- a/frontend/src/routes/(app)/projects/new/+page.svelte
+++ b/frontend/src/routes/(app)/projects/new/+page.svelte
@@ -34,7 +34,12 @@
planProjectWorkspaceFileRename,
validateProjectWorkspaceFileName
} from '../components/project-workspace-utils';
- import { planWorkspaceFileMove, workspaceFileBasename, workspaceFileLanguage } from '#lib/utils/workspace-files';
+ import {
+ planWorkspaceFileMove,
+ workspaceFileBasename,
+ workspaceFileLanguage,
+ workspaceReadOnlyMessage
+ } from '#lib/utils/workspace-files';
import { WorkspaceDraftState } from '#lib/components/workspace-editor/workspace-draft-state.svelte';
import {
composeTreeSplitProps,
@@ -421,23 +426,31 @@
/>
{:else if activeProjectTab.startsWith('file:')}
{@const relativePath = activeProjectTab.slice(5)}
- <CodePanel
- variant="plain"
- open={true}
- title={relativePath}
- language={workspaceFileLanguage(relativePath)}
- validationMode="none"
- bind:value={workspaceDraft.contents[relativePath]}
- bind:hasErrors={workspaceDraft.hasErrors[relativePath]}
- bind:validationReady={workspaceDraft.validationReady[relativePath]}
- fileId={`projects:new:file:${relativePath}`}
- originalValue=""
- enableDiff={true}
- editorContext={codeEditorContext}
- bind:outlineOpen={treeOutlineOpen}
- bind:diffOpen={treeDiffOpen}
- bind:commandPaletteOpen={treeCommandPaletteOpen}
- />
+ {#if workspaceDraft.binaryFiles[relativePath]}
+ <div
+ class="flex h-full min-h-0 items-center justify-center px-4 text-center text-sm text-muted-foreground"
+ >
+ {workspaceReadOnlyMessage('binary', projectWorkspaceMaxFileSizeMb)}
+ </div>
+ {:else}
+ <CodePanel
+ variant="plain"
+ open={true}
+ title={relativePath}
+ language={workspaceFileLanguage(relativePath)}
+ validationMode="none"
+ bind:value={workspaceDraft.contents[relativePath]}
+ bind:hasErrors={workspaceDraft.hasErrors[relativePath]}
+ bind:validationReady={workspaceDraft.validationReady[relativePath]}
+ fileId={`projects:new:file:${relativePath}`}
+ originalValue=""
+ enableDiff={true}
+ editorContext={codeEditorContext}
+ bind:outlineOpen={treeOutlineOpen}
+ bind:diffOpen={treeDiffOpen}
+ bind:commandPaletteOpen={treeCommandPaletteOpen}
+ />
+ {/if}
{/if}
{/key}
</div>
diff --git a/frontend/src/routes/(app)/swarm/stacks/new/+page.svelte b/frontend/src/routes/(app)/swarm/stacks/new/+page.svelte
index 6cdb8bd3a..ce079d4da 100644
--- a/frontend/src/routes/(app)/swarm/stacks/new/+page.svelte
+++ b/frontend/src/routes/(app)/swarm/stacks/new/+page.svelte
@@ -119,6 +119,7 @@
initialSelection: 'compose',
fallbackTab: 'compose',
pendingEntries: false,
+ allowBinary: false,
isFixedTab: (key) => key === 'compose' || key === 'env' || key === 'override',
isTabAvailable: (key) => key !== 'override' || overrideActive,
planCreate: planWorkspaceFileCreate,
diff --git a/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte b/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte
index c41053d42..d376bbacb 100644
--- a/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte
+++ b/frontend/src/routes/(app)/volumes/[volumeName]/+page.svelte
@@ -50,7 +50,7 @@
remapSelectedWorkspaceFileKey,
remapWorkspaceFileRecord,
removeWorkspaceFileRecord,
- readWorkspaceTextUpload,
+ readWorkspaceUpload,
validateWorkspaceFileName,
workspaceFileBasename,
workspaceFileLanguage,
@@ -105,6 +105,8 @@
let workspaceFileLoadErrors = $state<Record<string, string>>({});
let workspaceFileLoading = $state<Record<string, boolean>>({});
let workspaceRestoreRecords = $state<Record<string, true>>({});
+ let workspaceStagedFiles = $state<Record<string, File>>({});
+ let workspaceStagedUploadedText = $state<Record<string, string>>({});
const workspaceFileLoadVersions = new Map<string, number>();
let selectedWorkspaceFile = $state('');
let openWorkspaceTabs = $state<string[]>([]);
@@ -367,6 +369,8 @@
workspaceFileContents = remapWorkspaceFileRecord(workspaceFileContents, oldPath, newPath);
loadedWorkspaceFileContents = remapWorkspaceFileRecord(loadedWorkspaceFileContents, oldPath, newPath);
workspaceFileMetadata = remapWorkspaceFileRecord(workspaceFileMetadata, oldPath, newPath);
+ workspaceStagedFiles = remapWorkspaceFileRecord(workspaceStagedFiles, oldPath, newPath);
+ workspaceStagedUploadedText = remapWorkspaceFileRecord(workspaceStagedUploadedText, oldPath, newPath);
workspaceFileLoadErrors = remapWorkspaceFileRecord(workspaceFileLoadErrors, oldPath, newPath);
workspaceFileLoading = remapWorkspaceFileRecord(workspaceFileLoading, oldPath, newPath);
workspaceRestoreRecords = remapWorkspaceFileRecord(workspaceRestoreRecords, oldPath, newPath);
@@ -408,6 +412,8 @@
workspaceFileContents = removeWorkspaceFileRecord(workspaceFileContents, relativePath);
loadedWorkspaceFileContents = removeWorkspaceFileRecord(loadedWorkspaceFileContents, relativePath);
workspaceFileMetadata = removeWorkspaceFileRecord(workspaceFileMetadata, relativePath);
+ workspaceStagedFiles = removeWorkspaceFileRecord(workspaceStagedFiles, relativePath);
+ workspaceStagedUploadedText = removeWorkspaceFileRecord(workspaceStagedUploadedText, relativePath);
workspaceFileLoadErrors = removeWorkspaceFileRecord(workspaceFileLoadErrors, relativePath);
workspaceFileLoading = removeWorkspaceFileRecord(workspaceFileLoading, relativePath);
workspaceRestoreRecords = removeWorkspaceFileRecord(workspaceRestoreRecords, relativePath);
@@ -427,10 +433,32 @@
const relativePath = joinWorkspaceFilePath(parentPath, file.name);
const existing = visibleWorkspaceFiles.find((entry) => entry.relativePath === relativePath);
if (existing?.isDirectory) return;
- const upload = await readWorkspaceTextUpload(file, volumeWorkspaceMaxFileSizeMb);
+ const upload = await readWorkspaceUpload(file, volumeWorkspaceMaxFileSizeMb);
if (upload.error) return upload.error;
+ if (upload.binary) {
+ workspaceFileChanges = [...workspaceFileChanges, { operation: overwrite ? 'update_file' : 'create_file', relativePath }];
+ workspaceStagedFiles = { ...workspaceStagedFiles, [relativePath]: file };
+ workspaceFileContents = removeWorkspaceFileRecord(workspaceFileContents, relativePath);
+ workspaceStagedUploadedText = removeWorkspaceFileRecord(workspaceStagedUploadedText, relativePath);
+ workspaceFileMetadata = {
+ ...workspaceFileMetadata,
+ [relativePath]: {
+ path: `/${relativePath}`,
+ relativePath,
+ name: file.name,
+ size: file.size,
+ mimeType: file.type || 'application/octet-stream',
+ editable: false,
+ readOnlyReason: 'binary'
+ }
+ };
+ openWorkspaceFile(`file:${relativePath}`);
+ return;
+ }
const uploadedText = upload.content ?? '';
workspaceFileChanges = [...workspaceFileChanges, { operation: overwrite ? 'update_file' : 'create_file', relativePath }];
+ workspaceStagedFiles = { ...workspaceStagedFiles, [relativePath]: file };
+ workspaceStagedUploadedText = { ...workspaceStagedUploadedText, [relativePath]: uploadedText };
workspaceFileMetadata = {
...workspaceFileMetadata,
[relativePath]: {
@@ -443,9 +471,6 @@
}
};
workspaceFileContents = { ...workspaceFileContents, [relativePath]: uploadedText };
- if (loadedWorkspaceFileContents[relativePath] === undefined) {
- loadedWorkspaceFileContents = { ...loadedWorkspaceFileContents, [relativePath]: '' };
- }
openWorkspaceFile(`file:${relativePath}`);
}
@@ -490,6 +515,8 @@
workspaceFileContents = {};
loadedWorkspaceFileContents = {};
workspaceFileMetadata = {};
+ workspaceStagedFiles = {};
+ workspaceStagedUploadedText = {};
workspaceFileLoadErrors = {};
workspaceFileLoading = {};
workspaceRestoreRecords = {};
@@ -507,7 +534,13 @@
async function handleSaveVolumeWorkspace() {
if (!workspaceQuery.data || !canSaveWorkspace) return;
- const update = buildWorkspaceMultipartUpdate(workspaceFileChanges, workspaceFileContents, loadedWorkspaceFileContents);
+ const update = buildWorkspaceMultipartUpdate(
+ workspaceFileChanges,
+ workspaceFileContents,
+ loadedWorkspaceFileContents,
+ workspaceStagedFiles,
+ workspaceStagedUploadedText
+ );
handleApiResultWithCallbacks({
result: await tryCatch(
volumeWorkspaceService.updateWorkspace(