Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-02-01 03:46:29 +00:00
parent 2473f3f708
commit 4292c62ad1
8 changed files with 150 additions and 87 deletions

View File

@@ -113,7 +113,8 @@ export async function buildLicensePayload(row) {
repoFullName: row.repo_name,
repoUrl: null,
pluginName: row.label,
pluginVersion: null,
pluginVersion: row.last_used_version || null,
lastUsedVersion: row.last_used_version,
repo: null
};
}
@@ -134,7 +135,8 @@ export async function buildLicensePayload(row) {
repoFullName: info.fullName,
repoUrl: info.repoUrl,
pluginName: manifest?.plugin_name || info.name || row.label,
pluginVersion: manifest?.version || null,
pluginVersion: manifest?.version || row.last_used_version || null,
lastUsedVersion: row.last_used_version,
repo: repoEntry,
hostnames
};
@@ -152,25 +154,32 @@ export async function buildLicensePayload(row) {
repoFullName: row.repo_name,
repoUrl: repoEntry?.baseUrl ? `${repoEntry.baseUrl.replace(/\/$/, "")}/${row.repo_name}` : null,
pluginName: row.label,
pluginVersion: null,
pluginVersion: row.last_used_version || null,
lastUsedVersion: row.last_used_version,
repo: repoEntry,
hostnames
};
}
}
export async function touchLicenseHostname(license, hostname) {
export async function touchLicenseHostname(license, hostname, options = {}) {
const normalizedHost = normalizeHostname(hostname);
if (!normalizedHost) {
return { ok: false, error: "Ongeldige hostname." };
}
const trimmed = hostname.trim();
const rawVersion =
typeof options?.pluginVersion === "string" && options.pluginVersion.trim().length > 0
? options.pluginVersion.trim()
: null;
const pluginVersion = rawVersion ? rawVersion.slice(0, 64) : null;
const updateFields = [];
const params = [];
if (!license.primary_hostname_normalized) {
await db.query(
`UPDATE licenses SET primary_hostname = ?, primary_hostname_normalized = ?, last_version_check_at = NOW(), updated_at = NOW()
WHERE id = ?`,
[trimmed, normalizedHost, license.id]
);
updateFields.push("primary_hostname = ?", "primary_hostname_normalized = ?");
params.push(trimmed, normalizedHost);
} else if (license.primary_hostname_normalized !== normalizedHost) {
return {
ok: false,
@@ -178,9 +187,20 @@ export async function touchLicenseHostname(license, hostname) {
error: `Licentie hoort bij ${license.primary_hostname || "een andere site"}.`
};
} else {
await db.query(`UPDATE licenses SET last_version_check_at = NOW(), updated_at = NOW() WHERE id = ?`, [license.id]);
// No hostname change, but still keep the hostname casing in sync.
updateFields.push("primary_hostname = ?");
params.push(trimmed);
}
updateFields.push("last_version_check_at = NOW()", "updated_at = NOW()");
if (pluginVersion) {
updateFields.push("last_used_version = ?");
params.push(pluginVersion);
}
await db.query(`UPDATE licenses SET ${updateFields.join(", ")} WHERE id = ?`, [...params, license.id]);
await db.query(
`INSERT INTO license_hostnames (license_id, hostname, normalized, first_seen_at, last_seen_at, hits)
VALUES (?, ?, ?, NOW(), NOW(), 1)