refactor: standardize design

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-03-03 21:55:48 -05:00
parent 31a33d8758
commit a59dbff9f1
25 changed files with 994 additions and 306 deletions
+64 -75
View File
@@ -5,15 +5,16 @@
import { computed, ref } from 'vue'
import type { Ref, ComputedRef } from 'vue'
import { useProvidersStore } from '@FilesManager/stores/providersStore'
import { useServicesStore } from '@FilesManager/stores/servicesStore'
import { useNodesStore, ROOT_ID } from '@FilesManager/stores/nodesStore'
import type { FilterCondition, SortCondition, RangeCondition } from '@FilesManager/types/common'
import { FileCollectionObject } from '@FilesManager/models/collection'
import { FileEntityObject } from '@FilesManager/models/entity'
import { useProvidersStore } from '@DocumentsManager/stores/providersStore'
import { useServicesStore } from '@DocumentsManager/stores/servicesStore'
import { useNodesStore, ROOT_ID } from '@DocumentsManager/stores/nodesStore'
import type { ListFilter, ListSort, ListRange } from '@DocumentsManager/types/common'
import type { DocumentInterface } from '@DocumentsManager/types/document'
import { CollectionObject } from '@DocumentsManager/models/collection'
import { EntityObject } from '@DocumentsManager/models/entity'
// Base URL for file manager transfer endpoints
const TRANSFER_BASE_URL = '/m/file_manager'
const TRANSFER_BASE_URL = '/m/documents_manager'
export interface UseFileManagerOptions {
providerId: string
@@ -32,24 +33,24 @@ export function useFileManager(options: UseFileManagerOptions) {
const currentLocation: Ref<string> = ref(ROOT_ID)
// Loading/error state
const isLoading = computed(() => nodesStore.loading)
const isLoading = computed(() => nodesStore.transceiving)
const error = computed(() => nodesStore.error)
// Provider and service
const provider = computed(() => providersStore.getProvider(providerId))
const service = computed(() => servicesStore.getService(providerId, serviceId))
const rootId = computed(() => servicesStore.getRootId(providerId, serviceId) || ROOT_ID)
const provider = computed(() => providersStore.provider(providerId))
const service = computed(() => servicesStore.service(providerId, serviceId))
const rootId = computed(() => ROOT_ID)
// Current children
const currentChildren = computed(() =>
nodesStore.getChildren(providerId, serviceId, currentLocation.value)
)
const currentCollections: ComputedRef<FileCollectionObject[]> = computed(() =>
const currentCollections: ComputedRef<CollectionObject[]> = computed(() =>
nodesStore.getChildCollections(providerId, serviceId, currentLocation.value)
)
const currentEntities: ComputedRef<FileEntityObject[]> = computed(() =>
const currentEntities: ComputedRef<EntityObject[]> = computed(() =>
nodesStore.getChildEntities(providerId, serviceId, currentLocation.value)
)
@@ -77,7 +78,7 @@ export function useFileManager(options: UseFileManagerOptions) {
}
const currentNode = nodesStore.getNode(providerId, serviceId, currentLocation.value)
if (currentNode) {
await navigateTo(currentNode.in || ROOT_ID)
await navigateTo(currentNode.collection ? String(currentNode.collection) : ROOT_ID)
}
}
@@ -88,15 +89,14 @@ export function useFileManager(options: UseFileManagerOptions) {
// Refresh current location
const refresh = async (
filter?: FilterCondition[] | null,
sort?: SortCondition[] | null,
range?: RangeCondition | null
filter?: ListFilter,
sort?: ListSort,
range?: ListRange
) => {
await nodesStore.fetchNodes(
providerId,
serviceId,
currentLocation.value === ROOT_ID ? null : currentLocation.value,
false,
currentLocation.value === ROOT_ID ? ROOT_ID : currentLocation.value,
filter,
sort,
range
@@ -104,12 +104,12 @@ export function useFileManager(options: UseFileManagerOptions) {
}
// Create a new folder
const createFolder = async (label: string): Promise<FileCollectionObject> => {
const createFolder = async (label: string): Promise<CollectionObject> => {
return await nodesStore.createCollection(
providerId,
serviceId,
currentLocation.value === ROOT_ID ? ROOT_ID : currentLocation.value,
{ label }
{ label, owner: '' }
)
}
@@ -117,12 +117,22 @@ export function useFileManager(options: UseFileManagerOptions) {
const createFile = async (
label: string,
mime: string = 'application/octet-stream'
): Promise<FileEntityObject> => {
): Promise<EntityObject> => {
const properties: DocumentInterface = {
'@type': 'documents.properties',
urid: null,
size: 0,
label,
mime,
format: null,
encoding: null,
}
return await nodesStore.createEntity(
providerId,
serviceId,
currentLocation.value === ROOT_ID ? ROOT_ID : currentLocation.value,
{ label, mime }
properties
)
}
@@ -133,10 +143,22 @@ export function useFileManager(options: UseFileManagerOptions) {
throw new Error('Node not found')
}
if (node['@type'] === 'files.collection') {
return await nodesStore.modifyCollection(providerId, serviceId, nodeId, { label: newLabel })
if (node instanceof CollectionObject) {
return await nodesStore.updateCollection(providerId, serviceId, nodeId, {
label: newLabel,
owner: node.properties.owner,
})
} else {
return await nodesStore.modifyEntity(providerId, serviceId, node.in, nodeId, { label: newLabel })
const properties: DocumentInterface = {
'@type': 'documents.properties',
urid: node.properties.urid,
size: node.properties.size,
label: newLabel,
mime: node.properties.mime,
format: node.properties.format,
encoding: node.properties.encoding,
}
return await nodesStore.updateEntity(providerId, serviceId, node.collection, nodeId, properties)
}
}
@@ -147,61 +169,35 @@ export function useFileManager(options: UseFileManagerOptions) {
throw new Error('Node not found')
}
if (node['@type'] === 'files.collection') {
return await nodesStore.destroyCollection(providerId, serviceId, nodeId)
if (node instanceof CollectionObject) {
return await nodesStore.deleteCollection(providerId, serviceId, nodeId)
} else {
return await nodesStore.destroyEntity(providerId, serviceId, node.in, nodeId)
}
}
// Copy a node
const copyNode = async (nodeId: string, destinationId?: string | null) => {
const node = nodesStore.getNode(providerId, serviceId, nodeId)
if (!node) {
throw new Error('Node not found')
}
const destination = destinationId ?? currentLocation.value
if (node['@type'] === 'files.collection') {
return await nodesStore.copyCollection(providerId, serviceId, nodeId, destination)
} else {
return await nodesStore.copyEntity(providerId, serviceId, node.in, nodeId, destination)
}
}
// Move a node
const moveNode = async (nodeId: string, destinationId?: string | null) => {
const node = nodesStore.getNode(providerId, serviceId, nodeId)
if (!node) {
throw new Error('Node not found')
}
const destination = destinationId ?? currentLocation.value
if (node['@type'] === 'files.collection') {
return await nodesStore.moveCollection(providerId, serviceId, nodeId, destination)
} else {
return await nodesStore.moveEntity(providerId, serviceId, node.in, nodeId, destination)
return await nodesStore.deleteEntity(providerId, serviceId, node.collection, nodeId)
}
}
// Read file content
const readFile = async (entityId: string): Promise<string | null> => {
const node = nodesStore.getNode(providerId, serviceId, entityId)
if (!node || node['@type'] !== 'files.entity') {
if (!node || !(node instanceof EntityObject)) {
throw new Error('Entity not found')
}
return await nodesStore.readEntity(providerId, serviceId, node.in || ROOT_ID, entityId)
return await nodesStore.readEntity(providerId, serviceId, node.collection || ROOT_ID, entityId)
}
// Write file content
const writeFile = async (entityId: string, content: string): Promise<number> => {
const node = nodesStore.getNode(providerId, serviceId, entityId)
if (!node || node['@type'] !== 'files.entity') {
if (!node || !(node instanceof EntityObject)) {
throw new Error('Entity not found')
}
return await nodesStore.writeEntity(providerId, serviceId, node.in, entityId, content)
return await nodesStore.writeEntity(providerId, serviceId, node.collection, entityId, content)
}
// Get a URL suitable for inline viewing (img src / video src)
const getEntityUrl = (entityId: string, collectionId?: string | null): string => {
const collection = collectionId ?? currentLocation.value
return `${TRANSFER_BASE_URL}/download/entity/${encodeURIComponent(providerId)}/${encodeURIComponent(serviceId)}/${encodeURIComponent(collection)}/${encodeURIComponent(entityId)}`
}
// Download a single file
@@ -214,7 +210,6 @@ export function useFileManager(options: UseFileManagerOptions) {
window.open(url, '_blank')
}
// Download a collection (folder) as ZIP
const downloadCollection = (collectionId: string): void => {
// Use path parameters: /download/collection/{provider}/{service}/{identifier}
const url = `${TRANSFER_BASE_URL}/download/collection/${encodeURIComponent(providerId)}/${encodeURIComponent(serviceId)}/${encodeURIComponent(collectionId)}`
@@ -222,7 +217,6 @@ export function useFileManager(options: UseFileManagerOptions) {
window.open(url, '_blank')
}
// Download multiple items as ZIP archive
const downloadArchive = (ids: string[], name: string = 'download', collectionId?: string | null): void => {
const collection = collectionId ?? currentLocation.value
const params = new URLSearchParams({
@@ -244,12 +238,8 @@ export function useFileManager(options: UseFileManagerOptions) {
// Initialize - fetch providers, services, and initial nodes if autoFetch
const initialize = async () => {
if (!providersStore.initialized) {
await providersStore.fetchProviders()
}
if (!servicesStore.initialized) {
await servicesStore.fetchServices()
}
await providersStore.list()
await servicesStore.list({ [providerId]: true })
if (autoFetch) {
await refresh()
}
@@ -284,10 +274,9 @@ export function useFileManager(options: UseFileManagerOptions) {
createFile,
renameNode,
deleteNode,
copyNode,
moveNode,
readFile,
writeFile,
getEntityUrl,
downloadEntity,
downloadCollection,
downloadArchive,