Add type for download format and noImplicitReturns rule

This commit is contained in:
Kloon ImKloon 2023-09-13 12:47:15 +02:00
parent d2e81a6e77
commit 065e11ff2b
No known key found for this signature in database
GPG Key ID: CCF1C86A995C5B6A
7 changed files with 32 additions and 9 deletions

View File

@ -12,7 +12,7 @@ export async function fetch(url: string, password: string = "") {
false
);
const data = await res.json();
const data = (await res.json()) as Resource;
console.log(data);
data.url = `/share${url}`;
@ -33,12 +33,11 @@ export async function fetch(url: string, password: string = "") {
return data;
}
// Is this redundant code?
export function download(
format: any,
format: DownloadFormat,
hash: string,
token: string,
...files: any
...files: string[]
) {
let url = `${baseURL}/api/public/dl/${hash}`;

View File

@ -34,3 +34,13 @@ type ResourceType =
| "text"
| "blob"
| "textImmutable";
type DownloadFormat =
| "zip"
| "tar"
| "targz"
| "tarbz2"
| "tarxz"
| "tarlz4"
| "tarsz"
| null;

View File

@ -203,8 +203,8 @@ const error = ref<StatusError | null>(null);
const showLimit = ref<number>(100);
const password = ref<string>("");
const attemptedPasswordLogin = ref<boolean>(false);
const hash = ref<any>(null);
const token = ref<any>(null);
const hash = ref<string>("");
const token = ref<string>("");
const clip = ref<any>(null);
const $showSuccess = inject<IToastSuccess>("$showError")!;
@ -308,18 +308,21 @@ const isSingleFile = () =>
!req.value?.items[fileStore.selected[0]].isDir;
const download = () => {
if (!req.value) return false;
if (isSingleFile()) {
api.download(
null,
hash.value,
token.value,
req.value?.items[fileStore.selected[0]].path
req.value.items[fileStore.selected[0]].path
);
return;
return true;
}
layoutStore.showHover({
prompt: "download",
confirm: (format: any) => {
confirm: (format: DownloadFormat) => {
if (req.value === null) return false;
layoutStore.closeHovers();
@ -330,8 +333,11 @@ const download = () => {
}
api.download(format, hash.value, token.value, ...files);
return true;
},
});
return true;
};
const linkSelected = () => {

View File

@ -329,6 +329,8 @@ const save = async () => {
} catch (e: any) {
$showError(e);
}
return true;
};
// Parse the user-friendly input (e.g., "20M" or "1T") to bytes
const parseBytes = (input: string) => {

View File

@ -120,6 +120,7 @@ onMounted(() => {
singleClick.value = authStore.user.singleClick;
dateFormat.value = authStore.user.dateFormat;
layoutStore.loading = false;
return true;
});
const updatePassword = async (event: Event) => {

View File

@ -154,6 +154,8 @@ const deleteUser = async (e: Event) => {
$showError(err);
}
}
return true;
};
const save = async (event: Event) => {
event.preventDefault();
@ -183,5 +185,7 @@ const save = async (event: Event) => {
} catch (e: any) {
$showError(e);
}
return true;
};
</script>

View File

@ -8,6 +8,7 @@
"moduleResolution": "Node10",
"strict": true,
"sourceMap": true,
"noImplicitReturns": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,