forked from izu/student-web-if-development-kit
32 lines
992 B
JavaScript
32 lines
992 B
JavaScript
import { DocumentFormatter } from '../utils/document-formatter.js';
|
|
|
|
export class DirectusClient {
|
|
static API_BASE = 'https://api.ifuntanhub.dev';
|
|
|
|
static itemsUrl(collection) {
|
|
return `${this.API_BASE}/items/${collection}?limit=-1`;
|
|
}
|
|
|
|
static assetUrl(uuid) {
|
|
return `${this.API_BASE}/assets/${uuid}`;
|
|
}
|
|
|
|
static viewerUrl(item) {
|
|
const type = DocumentFormatter.fileTypeFromName(item.nama_berkas);
|
|
const params = new URLSearchParams({
|
|
id: item.file,
|
|
name: item.nama_berkas,
|
|
type,
|
|
});
|
|
return `viewer.html?${params.toString()}`;
|
|
}
|
|
|
|
static async fetchPublished(collection) {
|
|
const response = await fetch(this.itemsUrl(collection));
|
|
if (!response.ok) throw new Error(`Gagal memuat koleksi ${collection}.`);
|
|
const body = await response.json();
|
|
const items = body.data || [];
|
|
return items.filter(item => item.status === 'published');
|
|
}
|
|
}
|