fix (upload): issue uploading files

This commit is contained in:
MickaelK
2023-11-24 00:44:19 +11:00
parent 253cb8ceba
commit d811fdd21c
2 changed files with 20 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import { setup_cache_state } from "."; import { setup_cache_state } from ".";
import { currentBackend, currentShare } from "./cache_state.js";
const DB_VERSION = 4; const DB_VERSION = 4;
const FILE_PATH = "file_path"; const FILE_PATH = "file_path";
@ -331,7 +332,20 @@ export function setup_cache() {
cache = new DataFromMemory(); cache = new DataFromMemory();
if ("indexedDB" in window && window.indexedDB !== null) { if ("indexedDB" in window && window.indexedDB !== null) {
cache = new DataFromIndexedDB(); cache = new DataFromIndexedDB();
const currentPath = location.pathname.replace(/^\/.*?\//, "/");
return Promise.all([cache.db, setup_cache_state()]) return Promise.all([cache.db, setup_cache_state()])
.then(() => cache.update(FILE_PATH, [currentBackend(), currentShare(), currentPath], (response) => {
response.results = response.results.reduce((acc, file) => {
if (file.icon === "loading") {
cache.remove(FILE_PATH, [currentBackend(), currentShare(), file.path]);
cache.remove(FILE_CONTENT, [currentBackend(), currentShare(), file.path]);
return acc;
}
acc.push(file);
return acc;
}, []);
return response;
}))
.catch((err) => { .catch((err) => {
if (err === "INDEXEDDB_NOT_SUPPORTED") { if (err === "INDEXEDDB_NOT_SUPPORTED") {
// Firefox in private mode act like if it supports indexedDB but // Firefox in private mode act like if it supports indexedDB but

View File

@ -1,6 +1,6 @@
import Path from "path"; import Path from "path";
export function pathBuilder(path, filename, type = "file") { export function pathBuilder(path = "", filename = "", type = "file") {
const tmp = Path.resolve(path, filename); const tmp = Path.resolve(path, filename);
if (type === "file") { if (type === "file") {
return tmp; return tmp;
@ -9,21 +9,21 @@ export function pathBuilder(path, filename, type = "file") {
} }
} }
export function basename(path) { export function basename(path = "") {
return Path.basename(path); return Path.basename(path);
} }
export function dirname(path) { export function dirname(path = "") {
const dir = Path.dirname(path); const dir = Path.dirname(path);
if (dir === "/") return dir; if (dir === "/") return dir;
return dir + "/"; return dir + "/";
} }
export function filetype(path) { export function filetype(path = "") {
return path.slice(-1) === "/" ? "directory" : "file"; return path.slice(-1) === "/" ? "directory" : "file";
} }
export function absoluteToRelative(from, to) { export function absoluteToRelative(from = "", to = "") {
// remove any trace of file that would be interpreted by the path lib as a folder // remove any trace of file that would be interpreted by the path lib as a folder
from = from.replace(/\/[^\/]+$/, "/"); from = from.replace(/\/[^\/]+$/, "/");
let r = Path.relative(from, to); let r = Path.relative(from, to);
@ -36,7 +36,7 @@ export function absoluteToRelative(from, to) {
return r; return r;
} }
export function appendShareToUrl(link) { export function appendShareToUrl(link = "") {
let url = new window.URL(location.href); let url = new window.URL(location.href);
const share = url.searchParams.get("share"); const share = url.searchParams.get("share");