feat: enhance repository metadata resolution and build URL for plugin licenses
This commit is contained in:
@@ -34,6 +34,52 @@ try {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function buildRepoUrl(repoEntry) {
|
||||
if (!repoEntry) return null;
|
||||
if (repoEntry.provider === "gitea") {
|
||||
const base = (repoEntry.baseUrl || "").replace(/\/$/, "");
|
||||
return base && repoEntry.repo ? `${base}/${repoEntry.repo}` : null;
|
||||
}
|
||||
return `https://github.com/${repoEntry.repo}`;
|
||||
}
|
||||
|
||||
async function resolveRepoMetaFromRequest(body = {}) {
|
||||
const owner = typeof body.owner === "string" ? body.owner.trim() : "";
|
||||
const repository = typeof body.repository === "string" ? body.repository.trim() : "";
|
||||
if (!owner || !repository) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const provider = (body.provider || body.repoProvider || "github").toLowerCase();
|
||||
const baseUrl = body.baseUrl || body.repoBaseUrl || (provider === "github" ? "https://github.com" : null);
|
||||
|
||||
const repoEntry = normalizeRepoInput(
|
||||
{ repo: `${owner}/${repository}`, provider, baseUrl },
|
||||
{ repo: `${owner}/${repository}`, provider, baseUrl }
|
||||
);
|
||||
|
||||
if (!repoEntry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const info = await fetchRepo(repoEntry);
|
||||
const manifest = await fetchManifest(repoEntry, info.defaultBranch).catch(() => null);
|
||||
const releases = await fetchReleases(repoEntry).catch(() => []);
|
||||
const latestRelease = releases[0];
|
||||
const version = manifest?.version || latestRelease?.tag || latestRelease?.name || info.defaultBranch || null;
|
||||
const pluginName = manifest?.plugin_name || info.name || repository;
|
||||
|
||||
return {
|
||||
repoEntry,
|
||||
pluginName,
|
||||
version
|
||||
};
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
app.post("/api/auth/register", async (req, res) => {
|
||||
try {
|
||||
const { username, name, email, password } = req.body || {};
|
||||
@@ -388,7 +434,20 @@ app.post("/api/licenses/verify", async (req, res) => {
|
||||
}
|
||||
const license = await findLicenseByKey(String(key).trim());
|
||||
if (!license) {
|
||||
return res.status(404).json({ valid: false, error: "Licentie niet gevonden." });
|
||||
const repoMeta = await resolveRepoMetaFromRequest(req.body);
|
||||
const fallbackPayload = repoMeta
|
||||
? {
|
||||
pluginVersion: repoMeta.version,
|
||||
license: {
|
||||
pluginName: repoMeta.pluginName,
|
||||
pluginVersion: repoMeta.version,
|
||||
repoFullName: repoMeta.repoEntry.repo,
|
||||
repoUrl: buildRepoUrl(repoMeta.repoEntry),
|
||||
repo: repoMeta.repoEntry
|
||||
}
|
||||
}
|
||||
: {};
|
||||
return res.status(404).json({ valid: false, error: "Licentie niet gevonden.", ...fallbackPayload });
|
||||
}
|
||||
|
||||
const rawVersion = req.body?.currentVersion ?? req.body?.pluginVersion ?? null;
|
||||
|
||||
Reference in New Issue
Block a user