mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Fix detached ArrayBuffer error in CapacitorFSAdapter
This commit is contained in:
3 files changed
+19
-8
No files matched your search
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||||
import { encodeBase64, decodeBase64 } from '@std/encoding/base64';
|
import { Buffer } from 'buffer';
|
||||||
import path from 'path-browserify';
|
import path from 'path-browserify';
|
||||||
import type { JSRuntimeFS, DirectoryEntry } from './JSRuntime';
|
import type { JSRuntimeFS, DirectoryEntry } from './JSRuntime';
|
||||||
|
|
||||||
@@ -73,12 +73,15 @@ export class CapacitorFSAdapter implements JSRuntimeFS {
|
|||||||
path: normalizedPath,
|
path: normalizedPath,
|
||||||
directory: this.baseDirectory,
|
directory: this.baseDirectory,
|
||||||
});
|
});
|
||||||
|
let base64: string;
|
||||||
if (result.data instanceof Blob) {
|
if (result.data instanceof Blob) {
|
||||||
const base64 = await result.data.text();
|
base64 = await result.data.text();
|
||||||
return decodeBase64(base64);
|
|
||||||
} else {
|
} else {
|
||||||
return decodeBase64(result.data);
|
base64 = result.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode base64 and return as Buffer for compatibility with isomorphic-git
|
||||||
|
return Buffer.from(base64, 'base64');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +92,8 @@ export class CapacitorFSAdapter implements JSRuntimeFS {
|
|||||||
const normalizedPath = this.normalizePath(filePath);
|
const normalizedPath = this.normalizePath(filePath);
|
||||||
|
|
||||||
if (data instanceof Uint8Array) {
|
if (data instanceof Uint8Array) {
|
||||||
// Write binary data as base64 (no encoding specified)
|
// Write binary data as base64 using Buffer for consistency with readFile
|
||||||
const base64Data = encodeBase64(data);
|
const base64Data = Buffer.from(data).toString('base64');
|
||||||
await Filesystem.writeFile({
|
await Filesystem.writeFile({
|
||||||
path: normalizedPath,
|
path: normalizedPath,
|
||||||
directory: this.baseDirectory,
|
directory: this.baseDirectory,
|
||||||
@@ -185,6 +188,7 @@ export class CapacitorFSAdapter implements JSRuntimeFS {
|
|||||||
async stat(path: string): Promise<{
|
async stat(path: string): Promise<{
|
||||||
isDirectory(): boolean;
|
isDirectory(): boolean;
|
||||||
isFile(): boolean;
|
isFile(): boolean;
|
||||||
|
isSymbolicLink(): boolean;
|
||||||
size?: number;
|
size?: number;
|
||||||
mtimeMs?: number;
|
mtimeMs?: number;
|
||||||
}> {
|
}> {
|
||||||
@@ -198,8 +202,9 @@ export class CapacitorFSAdapter implements JSRuntimeFS {
|
|||||||
return {
|
return {
|
||||||
isDirectory: () => result.type === 'directory',
|
isDirectory: () => result.type === 'directory',
|
||||||
isFile: () => result.type === 'file',
|
isFile: () => result.type === 'file',
|
||||||
|
isSymbolicLink: () => false, // Capacitor doesn't support symlinks
|
||||||
size: result.size,
|
size: result.size,
|
||||||
mtimeMs: result.mtime,
|
mtimeMs: result.mtime ?? Date.now(), // Default to current time if not provided
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
// Create a proper Node.js-style error
|
// Create a proper Node.js-style error
|
||||||
@@ -218,6 +223,7 @@ export class CapacitorFSAdapter implements JSRuntimeFS {
|
|||||||
async lstat(path: string): Promise<{
|
async lstat(path: string): Promise<{
|
||||||
isDirectory(): boolean;
|
isDirectory(): boolean;
|
||||||
isFile(): boolean;
|
isFile(): boolean;
|
||||||
|
isSymbolicLink(): boolean;
|
||||||
size?: number;
|
size?: number;
|
||||||
mtimeMs?: number;
|
mtimeMs?: number;
|
||||||
}> {
|
}> {
|
||||||
@@ -231,8 +237,9 @@ export class CapacitorFSAdapter implements JSRuntimeFS {
|
|||||||
return {
|
return {
|
||||||
isDirectory: () => result.type === 'directory',
|
isDirectory: () => result.type === 'directory',
|
||||||
isFile: () => result.type === 'file',
|
isFile: () => result.type === 'file',
|
||||||
|
isSymbolicLink: () => false, // Capacitor doesn't support symlinks
|
||||||
size: result.size,
|
size: result.size,
|
||||||
mtimeMs: result.mtime,
|
mtimeMs: result.mtime ?? Date.now(), // Default to current time if not provided
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
// Create a proper Node.js-style error
|
// Create a proper Node.js-style error
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ export interface JSRuntimeFS {
|
|||||||
stat(path: string): Promise<{
|
stat(path: string): Promise<{
|
||||||
isDirectory(): boolean;
|
isDirectory(): boolean;
|
||||||
isFile(): boolean;
|
isFile(): boolean;
|
||||||
|
isSymbolicLink(): boolean;
|
||||||
size?: number;
|
size?: number;
|
||||||
mtimeMs?: number;
|
mtimeMs?: number;
|
||||||
}>;
|
}>;
|
||||||
lstat(path: string): Promise<{
|
lstat(path: string): Promise<{
|
||||||
isDirectory(): boolean;
|
isDirectory(): boolean;
|
||||||
isFile(): boolean;
|
isFile(): boolean;
|
||||||
|
isSymbolicLink(): boolean;
|
||||||
size?: number;
|
size?: number;
|
||||||
mtimeMs?: number;
|
mtimeMs?: number;
|
||||||
}>;
|
}>;
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ export class LightningFSAdapter implements JSRuntimeFS {
|
|||||||
async stat(path: string): Promise<{
|
async stat(path: string): Promise<{
|
||||||
isDirectory(): boolean;
|
isDirectory(): boolean;
|
||||||
isFile(): boolean;
|
isFile(): boolean;
|
||||||
|
isSymbolicLink(): boolean;
|
||||||
size?: number;
|
size?: number;
|
||||||
mtimeMs?: number;
|
mtimeMs?: number;
|
||||||
}> {
|
}> {
|
||||||
@@ -89,6 +90,7 @@ export class LightningFSAdapter implements JSRuntimeFS {
|
|||||||
async lstat(path: string): Promise<{
|
async lstat(path: string): Promise<{
|
||||||
isDirectory(): boolean;
|
isDirectory(): boolean;
|
||||||
isFile(): boolean;
|
isFile(): boolean;
|
||||||
|
isSymbolicLink(): boolean;
|
||||||
size?: number;
|
size?: number;
|
||||||
mtimeMs?: number;
|
mtimeMs?: number;
|
||||||
}> {
|
}> {
|
||||||
|
|||||||
Reference in new issue
Block a user