Skip to content

Commit

Permalink
feat: Show amount of pp counters in installed and available
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Nov 11, 2024
1 parent 3f7e8d6 commit f5512d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/server/assets/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<i class="icon-settings"></i>
Settings
</a>
<a href="/?tab=0" class="indent-left tab-item">Installed</a>
<a href="/?tab=1" class="tab-item">Available</a>
<a href="/?tab=0" class="indent-left tab-item">Installed{{LOCAL_AMOUNT}}</a>
<a href="/?tab=1" class="tab-item">Available{{AVAILABLE_AMOUNT}}</a>
<a class="tab-item"></a>
<div class="indent-left">
<input class="search-bar" type="text" placeholder="search" />
Expand Down
25 changes: 21 additions & 4 deletions packages/server/utils/counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ export function buildLocalCounters(res: http.ServerResponse, query?: string) {
return;
}

let html = content.replace('{{LIST}}', build || emptyNotice);
let html = content
.replace('{{LOCAL_AMOUNT}}', ` (${array.length})`)
.replace('{{AVAILABLE_AMOUNT}}', ``)
.replace('{{LIST}}', build || emptyNotice);
if (semver.gt(config.updateVersion, config.currentVersion)) {
html = html
.replace('{OLD}', config.currentVersion)
Expand All @@ -430,6 +433,8 @@ export async function buildExternalCounters(
query?: string
) {
let text = '';
let totalLocal = 0;
let totalAvailable = 0;

try {
const request: any = await fetch('https://osuck.net/tosu/api.json');
Expand Down Expand Up @@ -467,6 +472,9 @@ export async function buildExternalCounters(
}

text = build;

totalLocal = exists.length;
totalAvailable = json.length;
} catch (error) {
wLogger.error((error as any).message);
wLogger.debug(error);
Expand Down Expand Up @@ -498,7 +506,10 @@ export async function buildExternalCounters(
let responseHTML = submitCounterHTML;
responseHTML += text || noMoreCounters;

let html = content.replace('{{LIST}}', responseHTML);
let html = content
.replace('{{LOCAL_AMOUNT}}', ` (${totalLocal})`)
.replace('{{AVAILABLE_AMOUNT}}', ` (${totalAvailable})`)
.replace('{{LIST}}', responseHTML);
if (semver.gt(config.updateVersion, config.currentVersion)) {
html = html
.replace('{OLD}', config.currentVersion)
Expand Down Expand Up @@ -746,7 +757,10 @@ export function buildSettings(res: http.ServerResponse) {
return;
}

let html = content.replace('{{LIST}}', settings);
let html = content
.replace('{{LOCAL_AMOUNT}}', '')
.replace('{{AVAILABLE_AMOUNT}}', '')
.replace('{{LIST}}', settings);
if (semver.gt(config.updateVersion, config.currentVersion)) {
html = html
.replace('{OLD}', config.currentVersion)
Expand Down Expand Up @@ -788,7 +802,10 @@ export function buildInstructionLocal(res: http.ServerResponse) {
return;
}

let html = content.replace('{{LIST}}', pageContent);
let html = content
.replace('{{LOCAL_AMOUNT}}', '')
.replace('{{AVAILABLE_AMOUNT}}', '')
.replace('{{LIST}}', pageContent);
if (semver.gt(config.updateVersion, config.currentVersion)) {
html = html
.replace('{OLD}', config.currentVersion)
Expand Down

0 comments on commit f5512d1

Please sign in to comment.