basic text editor

This commit is contained in:
2025-09-06 01:21:13 +02:00
parent 73d3b2a27f
commit a4c2c039d2
13 changed files with 315 additions and 24 deletions

View File

@@ -2,6 +2,7 @@
import { fetchShareFile, getShare, listShareFiles } from '~/lib/api/shares';
import type { DirectoryEntry } from '~/shared/types';
import type { Share } from '~/shared/types/shares';
import { useImageViewer, useTextEditor } from '~/stores/viewers';
definePageMeta({
layout: 'share',
@@ -10,6 +11,9 @@ definePageMeta({
const warrenStore = useWarrenStore();
const route = useRoute();
const imageViewer = useImageViewer();
const textEditor = useTextEditor();
const entries = computed(() =>
warrenStore.current != null && warrenStore.current.dir != null
? warrenStore.current.dir.entries
@@ -127,8 +131,29 @@ async function onEntryClicked(entry: DirectoryEntry, event: MouseEvent) {
if (result.success) {
const url = URL.createObjectURL(result.data);
warrenStore.imageViewer.src = url;
imageViewer.open(url);
}
return;
}
if (entry.mimeType.startsWith('text/')) {
const result = await fetchShareFile(
share!.data.id,
entryPath,
password.value.length > 0 ? password.value : null
);
if (result.success) {
textEditor.open(
warrenStore.current.warrenId,
warrenStore.current.path,
entry,
result.data
);
}
return;
}
}

View File

@@ -5,12 +5,17 @@ import DirectoryListContextMenu from '~/components/DirectoryListContextMenu.vue'
import RenameEntryDialog from '~/components/actions/RenameEntryDialog.vue';
import { fetchFile, getWarrenDirectory, warrenRm } from '~/lib/api/warrens';
import type { DirectoryEntry } from '~/shared/types';
import { useImageViewer, useTextEditor } from '~/stores/viewers';
definePageMeta({
middleware: ['authenticated'],
});
const warrenStore = useWarrenStore();
const imageViewer = useImageViewer();
const textEditor = useTextEditor();
const loadingIndicator = useLoadingIndicator();
const uploadStore = useUploadStore();
const warrenPath = computed(() => useWarrenPath());
@@ -105,10 +110,32 @@ async function onEntryClicked(entry: DirectoryEntry, event: MouseEvent) {
warrenStore.current.path,
entry.name
);
if (result.success) {
const url = URL.createObjectURL(result.data);
warrenStore.imageViewer.src = url;
imageViewer.open(url);
}
return;
}
if (entry.mimeType.startsWith('text/')) {
const result = await fetchFile(
warrenStore.current.warrenId,
warrenStore.current.path,
entry.name
);
if (result.success) {
textEditor.open(
warrenStore.current.warrenId,
warrenStore.current.path,
entry,
result.data
);
}
return;
}
}