Fix ke 3 Env dan seafile
This commit is contained in:
@@ -1,3 +1,100 @@
|
|||||||
|
// import { getValidAuthToken } from "../../src/lib/seafile-auth-service";
|
||||||
|
|
||||||
|
// type CdnItem = {
|
||||||
|
// name: string;
|
||||||
|
// path: string;
|
||||||
|
// cdnUrl: string;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// type DirItem = {
|
||||||
|
// type: "file" | "dir";
|
||||||
|
// name: string;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const BASE_URL = process.env.SEAFILE_BASE_URL!;
|
||||||
|
// const REPO_ID = process.env.SEAFILE_REPO_ID!;
|
||||||
|
|
||||||
|
// // folder yang dishare (RELATIVE, tanpa slash depan)
|
||||||
|
// const DIR_TARGET = "asset-web";
|
||||||
|
|
||||||
|
// // 🔑 TOKEN DIRECTORY SHARE (/d/{token})
|
||||||
|
// const PUBLIC_SHARE_TOKEN = process.env.SEAFILE_PUBLIC_SHARE_TOKEN!;
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Ambil list file dari repo (butuh token sekali)
|
||||||
|
// */
|
||||||
|
// async function getDirItems(): Promise<DirItem[]> {
|
||||||
|
// const token = await getValidAuthToken();
|
||||||
|
|
||||||
|
// // Validasi bahwa semua variabel lingkungan telah diatur
|
||||||
|
// if (!BASE_URL) {
|
||||||
|
// throw new Error('SEAFILE_BASE_URL environment variable is not set');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!REPO_ID) {
|
||||||
|
// throw new Error('SEAFILE_REPO_ID environment variable is not set');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Bangun URL dan pastikan valid
|
||||||
|
// const url = `${BASE_URL}/api2/repos/${REPO_ID}/dir/?p=/${DIR_TARGET}`;
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// new URL(url); // Ini akan melempar error jika URL tidak valid
|
||||||
|
// } catch (error) {
|
||||||
|
// throw new Error(`Invalid URL constructed: ${url}. Error: ${error}`);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const res = await fetch(url, {
|
||||||
|
// headers: {
|
||||||
|
// Authorization: `Token ${token}`,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (!res.ok) {
|
||||||
|
// const text = await res.text();
|
||||||
|
// throw new Error(`Failed get dir items: ${text}`);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return res.json();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Build PUBLIC CDN URL
|
||||||
|
// */
|
||||||
|
// function buildPublicCdnUrl(fileName: string) {
|
||||||
|
// return `${BASE_URL}/d/${PUBLIC_SHARE_TOKEN}/files/?p=${encodeURIComponent(
|
||||||
|
// fileName,
|
||||||
|
// )}&raw=1`;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Ambil semua PUBLIC CDN URL
|
||||||
|
// */
|
||||||
|
// export async function getAllPublicCdnUrls(): Promise<CdnItem[]> {
|
||||||
|
// const items = await getDirItems();
|
||||||
|
|
||||||
|
// return items
|
||||||
|
// .filter((item) => item.type === "file")
|
||||||
|
// .map((file) => {
|
||||||
|
// const path = `${DIR_TARGET}/${file.name}`;
|
||||||
|
// return {
|
||||||
|
// name: file.name,
|
||||||
|
// path,
|
||||||
|
// cdnUrl: buildPublicCdnUrl(file.name),
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Run langsung (optional)
|
||||||
|
// */
|
||||||
|
// if (import.meta.main) {
|
||||||
|
// const data = await getAllPublicCdnUrls();
|
||||||
|
// console.log(data);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { getValidAuthToken } from "../../src/lib/seafile-auth-service";
|
import { getValidAuthToken } from "../../src/lib/seafile-auth-service";
|
||||||
|
|
||||||
type CdnItem = {
|
type CdnItem = {
|
||||||
@@ -11,29 +108,31 @@ type DirItem = {
|
|||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BASE_URL = process.env.SEAFILE_BASE_URL!;
|
// ✅ PAKAI ENV YANG BENAR
|
||||||
|
const BASE_URL = process.env.SEAFILE_URL!;
|
||||||
const REPO_ID = process.env.SEAFILE_REPO_ID!;
|
const REPO_ID = process.env.SEAFILE_REPO_ID!;
|
||||||
|
|
||||||
// folder yang dishare (RELATIVE, tanpa slash depan)
|
|
||||||
const DIR_TARGET = "asset-web";
|
|
||||||
|
|
||||||
// 🔑 TOKEN DIRECTORY SHARE (/d/{token})
|
|
||||||
const PUBLIC_SHARE_TOKEN = process.env.SEAFILE_PUBLIC_SHARE_TOKEN!;
|
const PUBLIC_SHARE_TOKEN = process.env.SEAFILE_PUBLIC_SHARE_TOKEN!;
|
||||||
|
|
||||||
|
// folder yang dishare (RELATIVE, TANPA slash depan)
|
||||||
|
const DIR_TARGET = "asset-web";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ambil list file dari repo (butuh token sekali)
|
* Ambil list file dari repo (token dipakai SEKALI)
|
||||||
*/
|
*/
|
||||||
async function getDirItems(): Promise<DirItem[]> {
|
async function getDirItems(): Promise<DirItem[]> {
|
||||||
|
if (!BASE_URL || !REPO_ID) {
|
||||||
|
throw new Error("SEAFILE env not configured correctly");
|
||||||
|
}
|
||||||
|
|
||||||
const token = await getValidAuthToken();
|
const token = await getValidAuthToken();
|
||||||
|
|
||||||
const res = await fetch(
|
const url = `${BASE_URL}/api2/repos/${REPO_ID}/dir/?p=/${DIR_TARGET}`;
|
||||||
`${BASE_URL}/api2/repos/${REPO_ID}/dir/?p=/${DIR_TARGET}`,
|
|
||||||
{
|
const res = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
@@ -44,11 +143,12 @@ async function getDirItems(): Promise<DirItem[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build PUBLIC CDN URL
|
* Build PUBLIC CDN URL (DIRECTORY SHARE)
|
||||||
*/
|
*/
|
||||||
function buildPublicCdnUrl(fileName: string) {
|
function buildPublicCdnUrl(fileName: string) {
|
||||||
|
const fullPath = `/${DIR_TARGET}/${fileName}`;
|
||||||
return `${BASE_URL}/d/${PUBLIC_SHARE_TOKEN}/files/?p=${encodeURIComponent(
|
return `${BASE_URL}/d/${PUBLIC_SHARE_TOKEN}/files/?p=${encodeURIComponent(
|
||||||
fileName,
|
fullPath,
|
||||||
)}&raw=1`;
|
)}&raw=1`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,20 +160,18 @@ export async function getAllPublicCdnUrls(): Promise<CdnItem[]> {
|
|||||||
|
|
||||||
return items
|
return items
|
||||||
.filter((item) => item.type === "file")
|
.filter((item) => item.type === "file")
|
||||||
.map((file) => {
|
.map((file) => ({
|
||||||
const path = `${DIR_TARGET}/${file.name}`;
|
name: file.name,
|
||||||
return {
|
path: `${DIR_TARGET}/${file.name}`,
|
||||||
name: file.name,
|
cdnUrl: buildPublicCdnUrl(file.name),
|
||||||
path,
|
}));
|
||||||
cdnUrl: buildPublicCdnUrl(file.name),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run langsung (optional)
|
* Run langsung
|
||||||
*/
|
*/
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
const data = await getAllPublicCdnUrls();
|
const data = await getAllPublicCdnUrls();
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
70
x.json
70
x.json
@@ -1,26 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"type": "repo",
|
|
||||||
"id": "8814bfe1-30d5-4e77-ab36-3122fa59a022",
|
|
||||||
"owner": "0535ccb6211642c0a628f521577863a0@auth.local",
|
|
||||||
"owner_name": "nico",
|
|
||||||
"owner_contact_email": "nico@bip.com",
|
|
||||||
"name": "desa-darmasaba",
|
|
||||||
"mtime": 1769484147,
|
|
||||||
"modifier_email": "0535ccb6211642c0a628f521577863a0@auth.local",
|
|
||||||
"modifier_contact_email": "nico@bip.com",
|
|
||||||
"modifier_name": "nico",
|
|
||||||
"mtime_relative": "<time datetime=\"2026-01-27T11:22:27\" is=\"relative-time\" title=\"Tue, 27 Jan 2026 11:22:27 +0800\" >1 minutes ago</time>",
|
|
||||||
"size": 184351,
|
|
||||||
"size_formatted": "180.0\u00a0KB",
|
|
||||||
"encrypted": false,
|
|
||||||
"permission": "rw",
|
|
||||||
"virtual": false,
|
|
||||||
"root": "",
|
|
||||||
"head_commit_id": "253fd9604e54804a22cbf701bcc551e311e4a428",
|
|
||||||
"version": 1,
|
|
||||||
"salt": ""
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "repo",
|
"type": "repo",
|
||||||
"id": "f0e9ee4a-fd13-49a2-81c0-f253951d063a",
|
"id": "f0e9ee4a-fd13-49a2-81c0-f253951d063a",
|
||||||
@@ -28,18 +6,40 @@
|
|||||||
"owner_name": "nico",
|
"owner_name": "nico",
|
||||||
"owner_contact_email": "nico@bip.com",
|
"owner_contact_email": "nico@bip.com",
|
||||||
"name": "My Library",
|
"name": "My Library",
|
||||||
"mtime": 1769483609,
|
"mtime": 1770175246,
|
||||||
"modifier_email": "0535ccb6211642c0a628f521577863a0@auth.local",
|
"modifier_email": "0535ccb6211642c0a628f521577863a0@auth.local",
|
||||||
"modifier_contact_email": "nico@bip.com",
|
"modifier_contact_email": "nico@bip.com",
|
||||||
"modifier_name": "nico",
|
"modifier_name": "nico",
|
||||||
"mtime_relative": "<time datetime=\"2026-01-27T11:13:29\" is=\"relative-time\" title=\"Tue, 27 Jan 2026 11:13:29 +0800\" >10 minutes ago</time>",
|
"mtime_relative": "<time datetime=\"2026-02-04T11:20:46\" is=\"relative-time\" title=\"Wed, 04 Feb 2026 11:20:46 +0800\" >1 day ago</time>",
|
||||||
"size": 19392875,
|
"size": 8418588,
|
||||||
"size_formatted": "18.5\u00a0MB",
|
"size_formatted": "8.0\u00a0MB",
|
||||||
"encrypted": false,
|
"encrypted": false,
|
||||||
"permission": "rw",
|
"permission": "rw",
|
||||||
"virtual": false,
|
"virtual": false,
|
||||||
"root": "",
|
"root": "",
|
||||||
"head_commit_id": "22374e711577dcfb152fe07921458302feb9970a",
|
"head_commit_id": "d864f18510f72fbf7ed8601d89ced2cb92466057",
|
||||||
|
"version": 1,
|
||||||
|
"salt": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "repo",
|
||||||
|
"id": "8814bfe1-30d5-4e77-ab36-3122fa59a022",
|
||||||
|
"owner": "0535ccb6211642c0a628f521577863a0@auth.local",
|
||||||
|
"owner_name": "nico",
|
||||||
|
"owner_contact_email": "nico@bip.com",
|
||||||
|
"name": "desa-darmasaba",
|
||||||
|
"mtime": 1769486218,
|
||||||
|
"modifier_email": "0535ccb6211642c0a628f521577863a0@auth.local",
|
||||||
|
"modifier_contact_email": "nico@bip.com",
|
||||||
|
"modifier_name": "nico",
|
||||||
|
"mtime_relative": "<time datetime=\"2026-01-27T11:56:58\" is=\"relative-time\" title=\"Tue, 27 Jan 2026 11:56:58 +0800\" >9 days ago</time>",
|
||||||
|
"size": 5064580,
|
||||||
|
"size_formatted": "4.8\u00a0MB",
|
||||||
|
"encrypted": false,
|
||||||
|
"permission": "rw",
|
||||||
|
"virtual": false,
|
||||||
|
"root": "",
|
||||||
|
"head_commit_id": "1ddc57ecf377741d0b3abcf5a56a9ed0612c553c",
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"salt": ""
|
"salt": ""
|
||||||
},
|
},
|
||||||
@@ -48,12 +48,12 @@
|
|||||||
"id": "9ef9d5e2-6df0-4635-ae1b-53ed52801524",
|
"id": "9ef9d5e2-6df0-4635-ae1b-53ed52801524",
|
||||||
"name": "RND",
|
"name": "RND",
|
||||||
"owner": "Organization",
|
"owner": "Organization",
|
||||||
"mtime": 1768959408,
|
"mtime": 1770263243,
|
||||||
"mtime_relative": "<time datetime=\"2026-01-21T09:36:48\" is=\"relative-time\" title=\"Wed, 21 Jan 2026 09:36:48 +0800\" >6 days ago</time>",
|
"mtime_relative": "<time datetime=\"2026-02-05T11:47:23\" is=\"relative-time\" title=\"Thu, 05 Feb 2026 11:47:23 +0800\" >28 minutes ago</time>",
|
||||||
"modifier_email": "dfa07fcb3e27453e969492855a2d6606@auth.local",
|
"modifier_email": "ecb9357c59024141bc1731a3e10900ea@auth.local",
|
||||||
"modifier_contact_email": "jun@bip.com",
|
"modifier_contact_email": "inno@bip.com",
|
||||||
"modifier_name": "jun",
|
"modifier_name": "inno",
|
||||||
"size": 1197897275,
|
"size": 1198188885,
|
||||||
"size_formatted": "1.1\u00a0GB",
|
"size_formatted": "1.1\u00a0GB",
|
||||||
"encrypted": false,
|
"encrypted": false,
|
||||||
"permission": "rw",
|
"permission": "rw",
|
||||||
@@ -62,8 +62,8 @@
|
|||||||
"share_from_contact_email": "wibu@bip.com",
|
"share_from_contact_email": "wibu@bip.com",
|
||||||
"share_type": "public",
|
"share_type": "public",
|
||||||
"root": "",
|
"root": "",
|
||||||
"head_commit_id": "5199e27babe4fd797e64beba62777a1dde58077b",
|
"head_commit_id": "f79f42f47c790bf5f14adb64bd644ec02aaf15bb",
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"salt": ""
|
"salt": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
22
x.sh
22
x.sh
@@ -1,23 +1,23 @@
|
|||||||
|
|
||||||
# ambil token
|
# # ambil token
|
||||||
curl -X POST https://cld-dkr-makuro-seafile.wibudev.com/api2/auth-token/ \
|
# curl -X POST https://cld-dkr-makuro-seafile.wibudev.com/api2/auth-token/ \
|
||||||
-d "username=nico@bip.com" \
|
# -d "username=nico@bip.com" \
|
||||||
-d "password=Production_123"
|
# -d "password=Production_123"
|
||||||
|
|
||||||
# ambil list repo / library
|
# # ambil list repo / library
|
||||||
|
|
||||||
TOKEN=20a19f4a04032215d50ce53292e6abdd38b9f806
|
# TOKEN=20a19f4a04032215d50ce53292e6abdd38b9f806
|
||||||
# curl -X GET \
|
# curl -X GET \
|
||||||
# https://cld-dkr-makuro-seafile.wibudev.com/api2/repos/ \
|
# https://cld-dkr-makuro-seafile.wibudev.com/api2/repos/ \
|
||||||
# -H "Authorization: Token $TOKEN"
|
# -H "Authorization: Token $TOKEN"
|
||||||
|
|
||||||
# REPO_NAME=desa-darmasaba
|
# REPO_NAME=desa-darmasaba
|
||||||
DIR_TARGET=asset-web
|
# DIR_TARGET=asset-web
|
||||||
|
|
||||||
REPO_ID=f0e9ee4a-fd13-49a2-81c0-f253951d063a
|
# REPO_ID=f0e9ee4a-fd13-49a2-81c0-f253951d063a
|
||||||
curl -X GET \
|
# curl -X GET \
|
||||||
"https://cld-dkr-makuro-seafile.wibudev.com/api2/repos/$REPO_ID/dir/?p=$DIR_TARGET" \
|
# "https://cld-dkr-makuro-seafile.wibudev.com/api2/repos/$REPO_ID/dir/?p=$DIR_TARGET" \
|
||||||
-H "Authorization: Token $TOKEN"
|
# -H "Authorization: Token $TOKEN"
|
||||||
|
|
||||||
# curl -X GET \
|
# curl -X GET \
|
||||||
# "https://cld-dkr-makuro-seafile.wibudev.com/api2/repos/$REPO_ID/file/?p=$DIR_TARGET/buku6.jpg" \
|
# "https://cld-dkr-makuro-seafile.wibudev.com/api2/repos/$REPO_ID/file/?p=$DIR_TARGET/buku6.jpg" \
|
||||||
|
|||||||
Reference in New Issue
Block a user