mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 18:20:30 +08:00
Implement project browsing
This commit is contained in:
+140
@@ -0,0 +1,140 @@
|
||||
import type { Config } from '@app/config';
|
||||
|
||||
export interface Project {
|
||||
id: string
|
||||
anchor: {
|
||||
stateHash: string
|
||||
stateHashFormat: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface Person {
|
||||
urn: string
|
||||
avatar: { emoji: string, background: { r: number, g: number, b: number } }
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
name: string
|
||||
description: string
|
||||
maintainers: Person[]
|
||||
}
|
||||
|
||||
export interface Author {
|
||||
avatar: string;
|
||||
email: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export enum ObjectType {
|
||||
Blob = "BLOB",
|
||||
Tree = "TREE",
|
||||
}
|
||||
|
||||
export interface CommitHeader {
|
||||
author: Author;
|
||||
committer: Author;
|
||||
committerTime: number;
|
||||
description: string;
|
||||
sha1: string;
|
||||
summary: string;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
name: string;
|
||||
objectType: ObjectType;
|
||||
lastCommit: CommitHeader;
|
||||
}
|
||||
|
||||
export interface Entry {
|
||||
path: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
export interface Blob {
|
||||
binary?: boolean;
|
||||
html?: boolean;
|
||||
content: string;
|
||||
path: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
export interface Tree {
|
||||
entries: Entry[];
|
||||
info: Info;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export async function getMetadata(urn: string, config: Config): Promise<Meta | null> {
|
||||
const api = import.meta.env.RADICLE_HTTP_API;
|
||||
const response = await fetch(`${api}/v1/projects/${urn}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
|
||||
if (! response.ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function getTree(
|
||||
urn: string,
|
||||
commit: string,
|
||||
path: string,
|
||||
config: Config
|
||||
): Promise<any | null> {
|
||||
if (! config.seed.api) return null;
|
||||
|
||||
const response = await fetch(`${config.seed.api}/v1/projects/${urn}/tree/${commit}/${path}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (! response.ok) {
|
||||
return null;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function getBlob(
|
||||
urn: string,
|
||||
commit: string,
|
||||
path: string,
|
||||
config: Config
|
||||
): Promise<Blob | null> {
|
||||
if (! config.seed.api) return null;
|
||||
|
||||
const response = await fetch(`${config.seed.api}/v1/projects/${urn}/blob/${commit}/${path}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (! response.ok) {
|
||||
return null;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function getReadme(
|
||||
urn: string,
|
||||
commit: string,
|
||||
config: Config
|
||||
): Promise<Blob | null> {
|
||||
if (! config.seed.api) return null;
|
||||
|
||||
const response = await fetch(`${config.seed.api}/v1/projects/${urn}/readme/${commit}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (! response.ok) {
|
||||
return null;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
Reference in New Issue
Block a user