Added product route

Added a single product route to get metadata and products list
This commit is contained in:
2026-01-28 00:14:13 +01:00
parent 4295d6bca3
commit 4e70d59c63
2 changed files with 44 additions and 1 deletions

View File

@@ -85,7 +85,7 @@ async function canAccess(productName, productPlatform) {
try {
const brikConfig = JSON.parse(await fs.promises.readFile(fixedPath))
if (!brikConfig.canAccess) {
if (!brikConfig.public) {
throw new DefaultError(403, "Forbidden", "Locked resource.", "InsuffisentPrivilegeException")
}
return { code: 200 }
@@ -98,9 +98,37 @@ async function canAccess(productName, productPlatform) {
}
async function getProduct(productName) {
const fixedPath = path.join(productsDataPath, productName, ".brikpkg")
const fileState = await fs.promises.exists(fixedPath, fs.constants.F_OK)
if (!fileState) {
throw new DefaultError(404, "Not found", "MissingDir", "NotFoundException")
}
try {
const brikPackage = JSON.parse(await fs.promises.readFile(fixedPath))
if (!brikPackage.public) {
throw new DefaultError(403, "Forbidden", "Locked resource.", "InsuffisentPrivilegeException")
}
return brikPackage
} catch (error) {
if (!error instanceof DefaultError) {
throw new DefaultError(500, "Please contact the maintener", "CONFIGURATION", "0x00")
}
throw error
}
}
async function getProducts() {
const files = await fs.promises.readdir(path.join(productsDataPath), { recursive: false })
return files
}
module.exports = {
getFile,
canAccess,
getProduct,
getFileSha1,
getProducts,
getProductFiles
}