From 43c31e5ffd3759de6b3721a64b80e2a2f1708f84 Mon Sep 17 00:00:00 2001 From: Syntax <2079305+TheUltDev@users.noreply.github.com> Date: Sat, 15 Feb 2025 12:04:29 -0600 Subject: [PATCH] refactor --- client/src/media/dir/hooks/use-dir-hfs.ts | 29 +++++++++---------- client/src/media/dir/hooks/use-dir-torrent.ts | 7 +++-- client/src/media/dir/hooks/use-dir-zip.ts | 4 +-- client/src/media/dir/hooks/use-entry-hfs.ts | 5 ++-- client/src/media/dir/stacks/entry-hfs.tsx | 5 ++-- client/src/media/dir/stacks/menu-hfs.tsx | 4 +-- client/src/media/dir/types/hfs.ts | 26 +++++++++-------- client/src/media/dir/types/torrent.ts | 19 ++++++++---- client/src/media/dir/types/zip.ts | 4 +-- client/src/media/dir/utils/hfs/meta.ts | 4 +-- translations/ar.po | 6 ++-- translations/en.po | 6 ++-- translations/es.po | 6 ++-- translations/ja.po | 6 ++-- translations/ko.po | 6 ++-- translations/ru.po | 6 ++-- 16 files changed, 75 insertions(+), 68 deletions(-) diff --git a/client/src/media/dir/hooks/use-dir-hfs.ts b/client/src/media/dir/hooks/use-dir-hfs.ts index 292a95fa..13bf49e2 100644 --- a/client/src/media/dir/hooks/use-dir-hfs.ts +++ b/client/src/media/dir/hooks/use-dir-hfs.ts @@ -11,11 +11,10 @@ import {getThumbnail} from '../utils/hfs/meta'; import {saveAs} from '../utils/hfs/fs'; import type {GestureResponderEvent} from 'react-native'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; -import type {HfsCtx} from 'media/dir/types/hfs'; +import type {HfsCtx, HfsFileEntry} from 'media/dir/types/hfs'; export function useDirHfs(path: string, tmp?: boolean): Omit { - const [list, setList] = useState([]); + const [list, setList] = useState([]); const hfs = useHfs(); const sel = useGet(media.selectors.getSelected); @@ -34,7 +33,7 @@ export function useDirHfs(path: string, tmp?: boolean): Omit { const refresh = useCallback(async () => { const showHidden = true; - const entries: HfsDirectoryEntry[] = []; + const entries: HfsFileEntry[] = []; const dirPath = path || '.'; try { // Check if path is valid @@ -76,13 +75,13 @@ export function useDirHfs(path: string, tmp?: boolean): Omit { } }, [hfs, path]); - const open = useCallback(async (entry: HfsDirectoryEntry, clearSel?: boolean) => { + const open = useCallback(async (entry: HfsFileEntry, clearSel?: boolean) => { if (!entry.isDirectory) return; nav(path ? `${path}/${entry.name}` : entry.name); if (clearSel) put(media.actions.selectBulk([])); }, [path, nav, put]); - const move = useCallback(async (from: HfsDirectoryEntry, to?: HfsDirectoryEntry) => { + const move = useCallback(async (from: HfsFileEntry, to?: HfsFileEntry) => { if (to) { const base = path ? `${path}/` : ''; const src = `${base}${from.name}`; @@ -94,7 +93,7 @@ export function useDirHfs(path: string, tmp?: boolean): Omit { } }, [hfs, path]); - const copy = useCallback(async (from: HfsDirectoryEntry, to?: HfsDirectoryEntry) => { + const copy = useCallback(async (from: HfsFileEntry, to?: HfsFileEntry) => { if (to) { await hfs?.copy?.(from.name, to.name); } else { @@ -102,13 +101,13 @@ export function useDirHfs(path: string, tmp?: boolean): Omit { } }, [hfs]); - const purge = useCallback(async (entry: HfsDirectoryEntry) => { + const purge = useCallback(async (entry: HfsFileEntry) => { const base = path ? `${path}/` : ''; const uri = `${base}${entry.name}`; await hfs?.deleteAll?.(uri); }, [hfs, path]); - const rename = useCallback(async (entry: HfsDirectoryEntry, name?: string) => { + const rename = useCallback(async (entry: HfsFileEntry, name?: string) => { if (name) { await hfs?.move?.(entry.name, name); } else { @@ -116,7 +115,7 @@ export function useDirHfs(path: string, tmp?: boolean): Omit { } }, [hfs]); - const select = useCallback((entry: HfsDirectoryEntry, event?: GestureResponderEvent) => { + const select = useCallback((entry: HfsFileEntry, event?: GestureResponderEvent) => { if (isZeego(event)) return; const [isShift, isCtrl] = [event?.shiftKey, event?.metaKey || event?.ctrlKey]; const fullPath = path ? `${path}/${entry.name}` : entry.name; @@ -132,7 +131,7 @@ export function useDirHfs(path: string, tmp?: boolean): Omit { })); }, [path, tmp, sel, open, put]); - const upload = useCallback(async (entry: HfsDirectoryEntry, files: File[]) => { + const upload = useCallback(async (entry: HfsFileEntry, files: File[]) => { if (!hfs) return; for (const file of files) { const data = await file.arrayBuffer(); @@ -143,22 +142,22 @@ export function useDirHfs(path: string, tmp?: boolean): Omit { } }, [hfs]); - const download = useCallback(async (entry: HfsDirectoryEntry) => { + const download = useCallback(async (entry: HfsFileEntry) => { if (entry.isFile) { const uri = path ? `${path}/${entry.name}` : entry.name; saveAs(await getData(uri, 'dataUrl'), entry.name); } }, [path]); - const compress = useCallback(async (entry: HfsDirectoryEntry) => { + const compress = useCallback(async (entry: HfsFileEntry) => { console.log('>> fs [compress]', entry); }, []); - const thumbnail = useCallback(async (entry: HfsDirectoryEntry) => { + const thumbnail = useCallback(async (entry: HfsFileEntry) => { return getThumbnail(path, entry); }, [path]); - const share = useCallback(async (entry: HfsDirectoryEntry) => { + const share = useCallback(async (entry: HfsFileEntry) => { console.log('>> fs [share]', entry); }, []); diff --git a/client/src/media/dir/hooks/use-dir-torrent.ts b/client/src/media/dir/hooks/use-dir-torrent.ts index 6407925e..f8a11cee 100644 --- a/client/src/media/dir/hooks/use-dir-torrent.ts +++ b/client/src/media/dir/hooks/use-dir-torrent.ts @@ -11,11 +11,11 @@ import media from 'media/store'; import type {Torrent, TorrentCtx, TorrentInfo, TorrentFileData, TorrentFileEntry} from 'media/dir/types/torrent'; import type {GestureResponderEvent} from 'react-native'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; +import type {HfsFileEntry} from 'media/dir/types/hfs'; export function useDirTorrent(path: string): TorrentCtx { - const buffer = useFile(path, 'arrayBuffer'); const {path: url} = usePath(); + const buffer = useFile(path, 'arrayBuffer'); const put = usePut(); const torrent: Torrent | null = useMemo(() => { @@ -38,7 +38,7 @@ export function useDirTorrent(path: string): TorrentCtx { const download = useCallback(async ( file: TorrentFileEntry, event?: GestureResponderEvent, - target?: HfsDirectoryEntry, + target?: HfsFileEntry, ) => { if (!torrent) return; const client = new Tor(); @@ -46,6 +46,7 @@ export function useDirTorrent(path: string): TorrentCtx { client.add(torrent.file, {store}, async ({files}) => { const item = files.find(e => e.path.split('/').slice(1).join('/') === file.path); const root = url ? `${url}/` : ''; + console.log('>> torrent [url]', url); const head = target?.name ? `${target.name}/` : ''; const dest = `${root}${head}${file.path}`; const handle = await web.getFileHandle(dest, {create: true}); diff --git a/client/src/media/dir/hooks/use-dir-zip.ts b/client/src/media/dir/hooks/use-dir-zip.ts index 3d7203a0..9d4855b2 100644 --- a/client/src/media/dir/hooks/use-dir-zip.ts +++ b/client/src/media/dir/hooks/use-dir-zip.ts @@ -10,7 +10,7 @@ import media from 'media/store'; import type {FS} from '@zip.js/zip.js'; import type {Zip, ZipCtx, ZipFileEntry} from 'media/dir/types/zip'; import type {GestureResponderEvent} from 'react-native'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; +import type {HfsFileEntry} from 'media/dir/types/hfs'; export function useDirZip(path: string): ZipCtx { const [zip, setZip] = useState(null); @@ -22,7 +22,7 @@ export function useDirZip(path: string): ZipCtx { const extract = useCallback(async ( file: ZipFileEntry, event?: GestureResponderEvent, - target?: HfsDirectoryEntry, + target?: HfsFileEntry, ) => { if (!zip) return; const source = zipfs.current?.getById(file.id); diff --git a/client/src/media/dir/hooks/use-entry-hfs.ts b/client/src/media/dir/hooks/use-entry-hfs.ts index c6275616..fb1bff55 100644 --- a/client/src/media/dir/hooks/use-entry-hfs.ts +++ b/client/src/media/dir/hooks/use-entry-hfs.ts @@ -9,13 +9,12 @@ import media from 'media/store'; import {is as isZip} from './use-entry-zip'; import {is as isTorrent} from './use-entry-torrent'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; import type {View, GestureResponderEvent} from 'react-native'; +import type {HfsCmd, HfsFileEntry} from 'media/dir/types/hfs'; import type {EntryHfsProps} from 'media/dir/stacks/entry-hfs'; import type {CleanupFn} from 'app/utils/dragdrop'; -import type {HfsCmd} from 'media/dir/types/hfs'; -export const {is, get, type} = $.tag('hfs'); +export const {is, get, type} = $.tag('hfs'); export function useEntryHfs({item, cmd, opt, tmp}: EntryHfsProps) { const [dropping, setDropping] = useState(false); diff --git a/client/src/media/dir/stacks/entry-hfs.tsx b/client/src/media/dir/stacks/entry-hfs.tsx index bf9e2175..b7cacd60 100644 --- a/client/src/media/dir/stacks/entry-hfs.tsx +++ b/client/src/media/dir/stacks/entry-hfs.tsx @@ -3,11 +3,10 @@ import {ListRow} from 'media/stacks/list/row'; import {MenuHfs} from 'media/dir/stacks/menu-hfs'; import {useEntryHfs} from 'media/dir/hooks/use-entry-hfs'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; -import type {HfsCmd, HfsOpt} from 'media/dir/types/hfs'; +import type {HfsCmd, HfsOpt, HfsFileEntry} from 'media/dir/types/hfs'; export interface EntryHfsProps { - item: HfsDirectoryEntry, + item: HfsFileEntry, cmd: HfsCmd, opt: HfsOpt, tmp?: boolean, diff --git a/client/src/media/dir/stacks/menu-hfs.tsx b/client/src/media/dir/stacks/menu-hfs.tsx index 14ebcad9..e7e69964 100644 --- a/client/src/media/dir/stacks/menu-hfs.tsx +++ b/client/src/media/dir/stacks/menu-hfs.tsx @@ -1,11 +1,11 @@ import {useLingui} from '@lingui/react/macro'; import {MenuContext} from 'app/stacks/float'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; import type {useEntryHfs} from 'media/dir/hooks/use-entry-hfs'; +import type {HfsFileEntry} from 'media/dir/types/hfs'; export interface MenuHfsProps extends React.PropsWithChildren { - item: HfsDirectoryEntry, + item: HfsFileEntry, cmd: ReturnType['cmd'], on?: (open: boolean) => void, } diff --git a/client/src/media/dir/types/hfs.ts b/client/src/media/dir/types/hfs.ts index b0ae29b4..a3bc9fc7 100644 --- a/client/src/media/dir/types/hfs.ts +++ b/client/src/media/dir/types/hfs.ts @@ -1,5 +1,5 @@ -import type {HfsDirectoryEntry} from 'react-exo/fs'; import type {GestureResponderEvent} from 'react-native'; +import type {HfsDirectoryEntry} from 'react-exo/fs'; import type {ListBarProps} from 'media/stacks/list/bar'; export interface Hfs { @@ -29,15 +29,17 @@ export type HfsOpt = { export type HfsCmd = { goUp: () => boolean, - share: (entry: HfsDirectoryEntry) => Promise, - open: (entry: HfsDirectoryEntry, clearSel?: boolean) => Promise, - copy: (entry: HfsDirectoryEntry) => Promise, - move: (from: HfsDirectoryEntry, to?: HfsDirectoryEntry) => Promise, - purge: (entry: HfsDirectoryEntry) => Promise, - rename: (entry: HfsDirectoryEntry) => Promise, - select: (entry: HfsDirectoryEntry, event?: GestureResponderEvent) => void, - upload: (entry: HfsDirectoryEntry, files: File[]) => Promise, - download: (entry: HfsDirectoryEntry) => Promise, - compress: (entry: HfsDirectoryEntry) => Promise, - thumbnail: (entry: HfsDirectoryEntry) => Promise, + share: (entry: HfsFileEntry) => Promise, + open: (entry: HfsFileEntry, clearSel?: boolean) => Promise, + copy: (entry: HfsFileEntry) => Promise, + move: (from: HfsFileEntry, to?: HfsFileEntry) => Promise, + purge: (entry: HfsFileEntry) => Promise, + rename: (entry: HfsFileEntry) => Promise, + select: (entry: HfsFileEntry, event?: GestureResponderEvent) => void, + upload: (entry: HfsFileEntry, files: File[]) => Promise, + download: (entry: HfsFileEntry) => Promise, + compress: (entry: HfsFileEntry) => Promise, + thumbnail: (entry: HfsFileEntry) => Promise, } + +export type HfsFileEntry = HfsDirectoryEntry & {} \ No newline at end of file diff --git a/client/src/media/dir/types/torrent.ts b/client/src/media/dir/types/torrent.ts index e7e8b61a..e8655dc2 100644 --- a/client/src/media/dir/types/torrent.ts +++ b/client/src/media/dir/types/torrent.ts @@ -1,5 +1,5 @@ import type {GestureResponderEvent} from 'react-native'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; +import type {HfsFileEntry} from 'media/dir/types/hfs'; export interface Torrent { file: File, @@ -19,21 +19,30 @@ export type TorrentCmd = { download: ( file: TorrentFileEntry, event?: GestureResponderEvent, - target?: HfsDirectoryEntry, + target?: HfsFileEntry, ) => Promise, } -export interface TorrentInfo { +export type TorrentFileEntry = TorrentFileData['files'][number]; + +export type TorrentInfo = { + /** Name of the torrent */ name: string, + /** List of URLs for the torrent */ urlList: string[], + /** List of announce URLs for the torrent */ announce: string[], + /** Comment for the torrent */ comment?: string, + /** Whether the torrent is private */ private?: boolean, + /** Date the torrent was created */ created?: Date, + /** Name of the creator of the torrent */ createdBy?: string, } -export interface TorrentFileData { +export type TorrentFileData = { /** Length of the file in bytes */ length: number; /** Array of files */ @@ -54,5 +63,3 @@ export interface TorrentFileData { /** Array of piece hashes */ pieces: string[]; } - -export type TorrentFileEntry = TorrentFileData['files'][number]; diff --git a/client/src/media/dir/types/zip.ts b/client/src/media/dir/types/zip.ts index e87e6412..19bd59ea 100644 --- a/client/src/media/dir/types/zip.ts +++ b/client/src/media/dir/types/zip.ts @@ -1,5 +1,5 @@ import type {GestureResponderEvent} from 'react-native'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; +import type {HfsFileEntry} from 'media/dir/types/hfs'; export interface Zip { date: { @@ -29,7 +29,7 @@ export type ZipCmd = { extract: ( entry: ZipFileEntry, event?: GestureResponderEvent, - target?: HfsDirectoryEntry, + target?: HfsFileEntry, ) => Promise, }; diff --git a/client/src/media/dir/utils/hfs/meta.ts b/client/src/media/dir/utils/hfs/meta.ts index 3fb3b601..e5ee92df 100644 --- a/client/src/media/dir/utils/hfs/meta.ts +++ b/client/src/media/dir/utils/hfs/meta.ts @@ -3,11 +3,11 @@ import {FileType} from 'media/file/types'; import {getRenderer} from 'media/file/utils/render'; import {toPath} from 'app/utils/formatting'; -import type {HfsDirectoryEntry} from 'react-exo/fs'; +import type {HfsFileEntry} from 'media/dir/types/hfs'; const THUMB_MAX_SIZE = 320; -export async function getThumbnail(path: string, item: HfsDirectoryEntry) { +export async function getThumbnail(path: string, item: HfsFileEntry) { if (item.isDirectory) return null; // Resolve path const uri = path ? `${path}/${item.name}` : item.name; diff --git a/translations/ar.po b/translations/ar.po index ae2f573d..30d35fbb 100644 --- a/translations/ar.po +++ b/translations/ar.po @@ -76,7 +76,7 @@ msgstr "إغلاق" msgid "Compress" msgstr "ضغط" -#: ../../client/src/media/hooks/use-media-controls.ts:72 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:55 msgid "Copy" msgstr "نسخ" @@ -166,7 +166,7 @@ msgstr "المستندات" msgid "Documents" msgstr "المستندات" -#: ../../client/src/media/hooks/use-media-controls.ts:91 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:44 msgid "Download" msgstr "تحميل" @@ -476,7 +476,7 @@ msgstr "الخدمات" msgid "Settings" msgstr "الإعدادات" -#: ../../client/src/media/hooks/use-media-controls.ts:268 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:30 msgid "Share" msgstr "مشاركة" diff --git a/translations/en.po b/translations/en.po index 36e59d07..270f781e 100644 --- a/translations/en.po +++ b/translations/en.po @@ -76,7 +76,7 @@ msgstr "Close" msgid "Compress" msgstr "Compress" -#: ../../client/src/media/hooks/use-media-controls.ts:72 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:55 msgid "Copy" msgstr "Copy" @@ -166,7 +166,7 @@ msgstr "Docs" msgid "Documents" msgstr "Documents" -#: ../../client/src/media/hooks/use-media-controls.ts:91 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:44 msgid "Download" msgstr "Download" @@ -476,7 +476,7 @@ msgstr "Services" msgid "Settings" msgstr "Settings" -#: ../../client/src/media/hooks/use-media-controls.ts:268 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:30 msgid "Share" msgstr "Share" diff --git a/translations/es.po b/translations/es.po index acebeb39..74421af1 100644 --- a/translations/es.po +++ b/translations/es.po @@ -76,7 +76,7 @@ msgstr "Cerrar" msgid "Compress" msgstr "Comprimir" -#: ../../client/src/media/hooks/use-media-controls.ts:72 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:55 msgid "Copy" msgstr "Copiar" @@ -166,7 +166,7 @@ msgstr "Documentos" msgid "Documents" msgstr "Documentos" -#: ../../client/src/media/hooks/use-media-controls.ts:91 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:44 msgid "Download" msgstr "Descargar" @@ -476,7 +476,7 @@ msgstr "Servicios" msgid "Settings" msgstr "Ajustes" -#: ../../client/src/media/hooks/use-media-controls.ts:268 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:30 msgid "Share" msgstr "Compartir" diff --git a/translations/ja.po b/translations/ja.po index 1d39d3d2..c031eda0 100644 --- a/translations/ja.po +++ b/translations/ja.po @@ -76,7 +76,7 @@ msgstr "閉じる" msgid "Compress" msgstr "圧縮" -#: ../../client/src/media/hooks/use-media-controls.ts:72 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:55 msgid "Copy" msgstr "コピー" @@ -166,7 +166,7 @@ msgstr "ドキュメント" msgid "Documents" msgstr "ドキュメント" -#: ../../client/src/media/hooks/use-media-controls.ts:91 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:44 msgid "Download" msgstr "ダウンロード" @@ -476,7 +476,7 @@ msgstr "サービス" msgid "Settings" msgstr "設定" -#: ../../client/src/media/hooks/use-media-controls.ts:268 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:30 msgid "Share" msgstr "共有" diff --git a/translations/ko.po b/translations/ko.po index 58b38b8f..1dcbe327 100644 --- a/translations/ko.po +++ b/translations/ko.po @@ -76,7 +76,7 @@ msgstr "닫기" msgid "Compress" msgstr "압축" -#: ../../client/src/media/hooks/use-media-controls.ts:72 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:55 msgid "Copy" msgstr "복사" @@ -166,7 +166,7 @@ msgstr "문서" msgid "Documents" msgstr "문서" -#: ../../client/src/media/hooks/use-media-controls.ts:91 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:44 msgid "Download" msgstr "다운로드" @@ -476,7 +476,7 @@ msgstr "서비스" msgid "Settings" msgstr "설정" -#: ../../client/src/media/hooks/use-media-controls.ts:268 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:30 msgid "Share" msgstr "공유" diff --git a/translations/ru.po b/translations/ru.po index b937c03c..ae744162 100644 --- a/translations/ru.po +++ b/translations/ru.po @@ -76,7 +76,7 @@ msgstr "Закрыть" msgid "Compress" msgstr "Сжать" -#: ../../client/src/media/hooks/use-media-controls.ts:72 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:55 msgid "Copy" msgstr "Копировать" @@ -166,7 +166,7 @@ msgstr "Документы" msgid "Documents" msgstr "Документы" -#: ../../client/src/media/hooks/use-media-controls.ts:91 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:44 msgid "Download" msgstr "Скачать" @@ -476,7 +476,7 @@ msgstr "Сервисы" msgid "Settings" msgstr "Настройки" -#: ../../client/src/media/hooks/use-media-controls.ts:268 +#: ../../client/src/media/dir/stacks/menu-hfs.tsx:30 msgid "Share" msgstr "Поделиться"