64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { axios, Page, PageResult } from "timi-web";
|
|
import { File, Repository, RepositoryView } from "@/types/Repository";
|
|
import { ActionLogView } from "@/types/Common.ts";
|
|
|
|
const BASE_URI = "/git/repository";
|
|
const API_HOST = import.meta.env.VITE_API;
|
|
|
|
async function view(name: string): Promise<RepositoryView> {
|
|
return axios.get(`${BASE_URI}/${name}`);
|
|
}
|
|
|
|
async function page(page: Page): Promise<PageResult<Repository>> {
|
|
return axios.post(`${BASE_URI}/list`, page);
|
|
}
|
|
|
|
async function pagePush(name: string, branch: string, page: Page): Promise<PageResult<ActionLogView>> {
|
|
return axios.post(`${BASE_URI}/${name}:${branch}/log/push`, page);
|
|
}
|
|
|
|
async function listFile(name: string, branch: string, path: string): Promise<File[]> {
|
|
return axios.get(`${BASE_URI}/${name}:${branch}/file/list${path}`);
|
|
}
|
|
|
|
function fileRawURL(name: string, branch: string, path: string): string {
|
|
return `${API_HOST}${BASE_URI}/${name}:${branch}/file/raw${path}`;
|
|
}
|
|
|
|
async function fileRawByURL(rawURL: string): Promise<ArrayBuffer> {
|
|
return axios({
|
|
url: rawURL,
|
|
method: "GET",
|
|
responseType: "arraybuffer"
|
|
});
|
|
}
|
|
|
|
async function fileRaw(name: string, branch: string, path: string): Promise<ArrayBuffer> {
|
|
return fileRawByURL(fileRawURL(name, branch, path));
|
|
}
|
|
|
|
async function fileMimeType(name: string, branch: string, path: string): Promise<string> {
|
|
return axios.get(`${BASE_URI}/${name}:${branch}/file/mime${path}`);
|
|
}
|
|
|
|
function downloadArchive(name: string, branch: string) {
|
|
window.open(`${API_HOST}${BASE_URI}/${name}:${branch}/archive`);
|
|
}
|
|
|
|
async function pageLog(page: Page): Promise<PageResult<ActionLogView>> {
|
|
return axios.post(`${BASE_URI}/log`, page);
|
|
}
|
|
|
|
export default {
|
|
view,
|
|
page,
|
|
pagePush,
|
|
listFile,
|
|
fileRaw,
|
|
fileRawURL,
|
|
fileRawByURL,
|
|
fileMimeType,
|
|
downloadArchive,
|
|
pageLog
|
|
};
|