const response = await api.get(`/v1/packages/${uuid}/filelist`);
return response.data;
}
+
+export async function fetchPackageFilePayload(pkg: Package, path: string): Promise<string> {
+ const response = await fetch(`/packages/${pkg.uuid}/download${path}`);
+
+ return await response.text();
+}
<!-- Actions -->
<td class="has-text-right">
<div class="buttons are-small is-justify-content-end">
- <a class="button" v-if="fileIsViewable(file)" href="#">
+ <RouterLink class="button" v-if="fileIsViewable(file)"
+ :to="{
+ name : 'package-file',
+ params : {
+ uuid : pkg.uuid,
+ path : file.path,
+ }
+ }">
<Icon icon="magnifying-glass" :title="$t('View')" />
- </a>
+ </RouterLink>
<a class="button" v-if="fileIsDownloadable(file)"
download :href="`/packages/${pkg.uuid}/download${file.path}`">
import { onMounted, ref } from "vue";
// API
-import type { Package } from "@/api/packages";
-import { fetchPackage } from "@/api/packages";
+import type { Package, File } from "@/api/packages";
+import {
+ fetchPackage,
+ fetchPackageFilelist,
+ fetchPackageFilePayload
+} from "@/api/packages";
export function usePackage(uuid: string) {
const pkg = ref<Package>();
pkg.value = await fetchPackage(uuid);
}
+ // Fetch the filelist
+ async function getPackageFilelist(): Promise<File[]> {
+ return fetchPackageFilelist(uuid);
+ }
+
+ // Fetch the payload of a single file
+ async function getPackageFilePayload(path: string): Promise<string> {
+ if (!pkg.value)
+ throw new Error("Package ${uuid} not loaded");
+
+ return fetchPackageFilePayload(pkg.value, path);
+ }
+
return {
pkg,
loadPackage,
+ getPackageFilelist,
+ getPackageFilePayload,
};
}
import MirrorsView from "../views/MirrorsView.vue"
import NotFoundView from "../views/NotFoundView.vue"
import PackageByUUIDView from "../views/PackageByUUIDView.vue"
+import PackageFileView from "../views/PackageFileView.vue"
import PackagesView from "../views/PackagesView.vue"
const router = createRouter({
component: PackageByUUIDView,
},
+ // Package File
+ {
+ path: "/packages/:uuid/files/:path(.*)*",
+ name: "package-file",
+ component: PackageFileView,
+ props: true,
+ },
+
// 404 - Not Found
{
path: "/:pathMatch(.*)*",
--- /dev/null
+<script setup lang="ts">
+ import { ref, onMounted } from "vue";
+
+ // Fetch the package UUID and path from the URL
+ const { uuid, path } = defineProps<{
+ uuid: string,
+ path: string,
+ }>();
+
+ // Fetch the package
+ import { usePackage } from "@/composables/packages";
+ const { pkg, loadPackage, getPackageFilePayload } = usePackage(uuid);
+
+ const content = ref("");
+ const loading = ref(true);
+ const error = ref<Error | null>(null);
+
+ onMounted(async () => {
+ await loadPackage();
+
+ // Fetch the payload
+ try {
+ content.value = await getPackageFilePayload(path);
+ } catch (e) {
+ error.value = e as Error;
+ } finally {
+ loading.value = false;
+ }
+ });
+</script>
+
+<template>
+ <Section :title="path">
+ <Container>
+ <Loader v-if="loading" />
+
+ <Notification v-else-if="error" is-danger>
+ {{ error }}
+ </Notification>
+
+ <div v-else>
+ <pre v-text="content" />
+ </div>
+ </Container>
+ </Section>
+</template>