diff --git a/src/api/document.ts b/src/api/document.ts new file mode 100644 index 0000000..a0fe108 --- /dev/null +++ b/src/api/document.ts @@ -0,0 +1,80 @@ +import type { StorageFile } from '@/interface/response/storage' + +const API_URI = import.meta.env.VITE_API_URI_CONFIG + +export async function getDocumentList(volume: string, id: string) { + const res = await fetch(`${API_URI}/document/${volume}/${id}`, { + headers: { + Accept: 'application/json', + }, + }) + + if (res && res.ok) { + return (await res.json()) as StorageFile + } + return false +} + +export async function getDocumentInfo( + volume: string, + id: string, + file: string +) { + const res = await fetch(`${API_URI}/document/${volume}/${id}/${file}`, { + headers: { + Accept: 'application/json', + }, + }) + + if (res && res.ok) { + return (await res.json()) as StorageFile & { downloadUrl: string } + } + return false +} + +const util = { + formatBytes: (bytes: number, decimals = 2) => { + if (!+bytes) return '0 Bytes' + + const k = 1024 + const dm = decimals < 0 ? 0 : decimals + const sizes = [ + 'Bytes', + 'KiB', + 'MiB', + 'GiB', + 'TiB', + 'PiB', + 'EiB', + 'ZiB', + 'YiB', + ] + const i = Math.floor(Math.log(bytes) / Math.log(k)) + + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` + }, + download: async (url: string, name?: string) => { + await fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .then((res) => res.blob()) + .then((blob) => { + const a = document.createElement('a') + a.href = window.URL.createObjectURL(blob) + a.download = name ?? 'download' + a.click() + a.remove() + }) + }, +} + +const doc = { + list: getDocumentList, + info: getDocumentInfo, + util, +} + +export default doc diff --git a/src/assets/cover.png b/src/assets/cover.png new file mode 100644 index 0000000..e4df1a3 Binary files /dev/null and b/src/assets/cover.png differ diff --git a/src/interface/response/storage.ts b/src/interface/response/storage.ts new file mode 100644 index 0000000..b8d0c24 --- /dev/null +++ b/src/interface/response/storage.ts @@ -0,0 +1,20 @@ +export interface StorageFile { + pathname: string + + fileName: string + fileSize: number + fileType: string + + title: string + description: string + category: string[] + keyword: string[] + + path: string + upload: boolean + + updatedAt: string | Date + updatedBy: string + createdAt: string | Date + createdBy: string +} diff --git a/src/router/index.ts b/src/router/index.ts index 172b1ec..9d3da1b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -2,23 +2,23 @@ import { createRouter, createWebHistory } from 'vue-router' /* import HomeView from '@/views/HomeView.vue' */ -const MainLayout = () => import("@/views/MainLayout.vue"); -const HomeView = () => import("@/views/HomeView.vue"); +const MainLayout = () => import('@/views/MainLayout.vue') +const HomeView = () => import('@/views/HomeView.vue') const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { - path: '/', + path: '/:id', name: 'home', component: MainLayout, - children:[ + children: [ { - path: "/", - name: "HomeView", + path: '/:id', + name: 'HomeView', component: HomeView, }, - ] + ], }, { path: '/:pathMatch(.*)*', @@ -31,8 +31,8 @@ const router = createRouter({ ], }) -router.beforeEach((to, from, next) => { - next(); +router.beforeEach((_to, _from, next) => { + next() }) export default router diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 2da31b8..cc2df7e 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -1,51 +1,128 @@ - + -