fix: cap file not appearing
This commit is contained in:
@@ -32,6 +32,7 @@ import { language } from "src/lang";
|
|||||||
import { startObserveDom } from "../observer";
|
import { startObserveDom } from "../observer";
|
||||||
import { removeDefaultHandler } from "src/main";
|
import { removeDefaultHandler } from "src/main";
|
||||||
import { updateGuisize } from "../gui/guisize";
|
import { updateGuisize } from "../gui/guisize";
|
||||||
|
import { encodeCapKeySafe } from "./mobileStorage";
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
export const isTauri = !!window.__TAURI__
|
export const isTauri = !!window.__TAURI__
|
||||||
@@ -120,13 +121,13 @@ export async function getFileSrc(loc:string) {
|
|||||||
}
|
}
|
||||||
if(Capacitor.isNativePlatform()){
|
if(Capacitor.isNativePlatform()){
|
||||||
if(!await checkCapFileExists({
|
if(!await checkCapFileExists({
|
||||||
path: loc,
|
path: encodeCapKeySafe(loc),
|
||||||
directory: CapFS.Directory.External
|
directory: CapFS.Directory.External
|
||||||
})){
|
})){
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
const uri = await CapFS.Filesystem.getUri({
|
const uri = await CapFS.Filesystem.getUri({
|
||||||
path: loc,
|
path: encodeCapKeySafe(loc),
|
||||||
directory: CapFS.Directory.External
|
directory: CapFS.Directory.External
|
||||||
})
|
})
|
||||||
return Capacitor.convertFileSrc(uri.uri)
|
return Capacitor.convertFileSrc(uri.uri)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import * as CapFS from '@capacitor/filesystem'
|
import * as CapFS from '@capacitor/filesystem'
|
||||||
|
|
||||||
function encodeKeySafe(oldKey:string){
|
export function encodeCapKeySafe(oldKey:string){
|
||||||
return oldKey.replace(/_/g, '__').replace(/\//g, '_s').replace(/\./g, '_d').replace(/\$/g, '_t').replace(/-/g, '_h').replace(/:/g, '_c') + '.bin'
|
return oldKey.replace(/_/g, '__').replace(/\//g, '_s').replace(/\./g, '_d').replace(/\$/g, '_t').replace(/-/g, '_h').replace(/:/g, '_c') + '.bin'
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeKeySafe(newKey:string){
|
export function decodeCapKeySafe(newKey:string){
|
||||||
newKey = newKey.substring(0, newKey.length-4)
|
newKey = newKey.substring(0, newKey.length-4)
|
||||||
return newKey.replace(/_c/g, ':').replace(/_h/g, '-').replace(/_t/g, '$').replace(/_d/g, '.').replace(/_s/g, '/').replace(/__/g, '_')
|
return newKey.replace(/_c/g, ':').replace(/_h/g, '-').replace(/_t/g, '$').replace(/_d/g, '.').replace(/_s/g, '/').replace(/__/g, '_')
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ function decodeKeySafe(newKey:string){
|
|||||||
export class MobileStorage{
|
export class MobileStorage{
|
||||||
async setItem(key:string, value:Uint8Array) {
|
async setItem(key:string, value:Uint8Array) {
|
||||||
await CapFS.Filesystem.writeFile({
|
await CapFS.Filesystem.writeFile({
|
||||||
path: encodeKeySafe(key),
|
path: encodeCapKeySafe(key),
|
||||||
data: Buffer.from(value).toString('base64'),
|
data: Buffer.from(value).toString('base64'),
|
||||||
directory: CapFS.Directory.External,
|
directory: CapFS.Directory.External,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
@@ -22,7 +22,7 @@ export class MobileStorage{
|
|||||||
async getItem(key:string):Promise<Buffer> {
|
async getItem(key:string):Promise<Buffer> {
|
||||||
try {
|
try {
|
||||||
const b64 = await CapFS.Filesystem.readFile({
|
const b64 = await CapFS.Filesystem.readFile({
|
||||||
path: encodeKeySafe(key),
|
path: encodeCapKeySafe(key),
|
||||||
directory: CapFS.Directory.External,
|
directory: CapFS.Directory.External,
|
||||||
})
|
})
|
||||||
return Buffer.from(b64.data as string, 'base64')
|
return Buffer.from(b64.data as string, 'base64')
|
||||||
@@ -41,11 +41,11 @@ export class MobileStorage{
|
|||||||
directory: CapFS.Directory.External,
|
directory: CapFS.Directory.External,
|
||||||
})
|
})
|
||||||
|
|
||||||
return files.files.map(f=>decodeKeySafe(f.name))
|
return files.files.map(f=>decodeCapKeySafe(f.name))
|
||||||
}
|
}
|
||||||
async removeItem(key:string){
|
async removeItem(key:string){
|
||||||
await CapFS.Filesystem.deleteFile({
|
await CapFS.Filesystem.deleteFile({
|
||||||
path: encodeKeySafe(key),
|
path: encodeCapKeySafe(key),
|
||||||
directory: CapFS.Directory.External,
|
directory: CapFS.Directory.External,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ export async function capStorageInvestigation(){
|
|||||||
})
|
})
|
||||||
|
|
||||||
for(const file of files.files){
|
for(const file of files.files){
|
||||||
const key = decodeKeySafe(file.name)
|
const key = decodeCapKeySafe(file.name)
|
||||||
const size = file.size
|
const size = file.size
|
||||||
investResults.push({key, size: byteLengthToString(size)})
|
investResults.push({key, size: byteLengthToString(size)})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user