Skip to content

Commit

Permalink
feat: Instruction page
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark authored and KotRikD committed Feb 28, 2024
1 parent 4518544 commit 59c1741
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/server/assets/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
rel="stylesheet">

<link rel="stylesheet" href="/homepage.min.css">
<title>Counters dashboard</title>
<title>tosu dashboard</title>
<style>

</style>
Expand All @@ -31,6 +31,7 @@
<a href="/?tab=0" class="tab-item">Installed</a>
<a href="/?tab=1" class="tab-item">Available</a>
<a href="/?tab=2" class="tab-item">Settings</a>
<a href="/?tab=3" class="tab-item">How to add counter</a>
<div class="indent-left">
<input class="search-bar" type="text" placeholder="search">
<!-- <a href="https://github.com/cyperdark/osu-counters/?tab=readme-ov-file#how-to-submit-pp-counter" target="_blank" class="button submit-button">Submit</a> -->
Expand Down
5 changes: 5 additions & 0 deletions packages/server/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import path from 'path';
import { HttpServer, getContentType, sendJson } from '../index';
import {
buildExternalCounters,
buildInstructionLocal,
buildLocalCounters,
buildSettings
} from '../utils/counters';
Expand Down Expand Up @@ -332,6 +333,10 @@ export default function buildBaseApi(app: HttpServer) {
return buildSettings(res);
}

if (req.query?.tab == '3') {
return buildInstructionLocal(res);
}

return buildLocalCounters(res);
}

Expand Down
87 changes: 75 additions & 12 deletions packages/server/utils/counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ function rebuildJSON({
const name = nameHTML.replace('{NAME}', item.name);
const author = authorHTML.replace('{AUTHOR}', item.author);

const counterName =
(item.author || '').toLowerCase() == 'local'
? item.name
: `${item.name} by ${item.author}`;

const links = item.authorlinks
.map((r) => {
const domain =
Expand All @@ -118,38 +123,50 @@ function rebuildJSON({
const iframe = iframeHTML
.replace(
'{URL}',
`http://${config.serverIP}:${config.serverPort}/${item.name} by ${item.author}/`
`http://${config.serverIP}:${config.serverPort}/${counterName}/`
)
.replace(
'{WIDTH}',
item.resolution[0] == -1 ? '500' : `${item.resolution[0]}px`
item.resolution[0] == -1
? '500px'
: item.resolution[0] == -2
? '100%'
: `${item.resolution[0]}px`
)
.replace(
'{HEIGHT}',
item.resolution[1] == -1 ? '500' : `${item.resolution[1]}px`
item.resolution[1] == -1 ? '500px' : `${item.resolution[1]}px`
);

const metadata = metadataHTML
.replace(
'{COPY_URL}',
`http://${config.serverIP}:${config.serverPort}/${item.name} by ${item.author}/`
`http://${config.serverIP}:${config.serverPort}/${counterName}/`
)
.replace('{TEXT_URL}', `/${item.name} by ${item.author}/`)
.replace('{TEXT_URL}', `/${counterName}/`)
.replace(
'{COPY_X}',
item.resolution[0] == -1 ? 'ANY' : item.resolution[0].toString()
item.resolution[0] == -1 || item.resolution[0] == -2
? 'ANY'
: item.resolution[0].toString()
)
.replace(
'{X}',
item.resolution[0] == -1 ? 'ANY' : item.resolution[0].toString()
item.resolution[0] == -1 || item.resolution[0] == -2
? 'ANY'
: item.resolution[0].toString()
)
.replace(
'{COPY_Y}',
item.resolution[1] == -1 ? 'ANY' : item.resolution[1].toString()
item.resolution[1] == -1 || item.resolution[1] == -2
? 'ANY'
: item.resolution[1].toString()
)
.replace(
'{Y}',
item.resolution[1] == -1 ? 'ANY' : item.resolution[1].toString()
item.resolution[1] == -1 || item.resolution[1] == -2
? 'ANY'
: item.resolution[1].toString()
);

const button = item.downloadLink
Expand Down Expand Up @@ -190,14 +207,34 @@ function getLocalCounters() {
config.staticFolderPath ||
path.join(path.dirname(process.execPath), 'static');

const countersList = recursiveFilesSearch({
const countersListTXT = recursiveFilesSearch({
dir: staticPath,
fileList: [],
filename: 'metadata.txt'
});

const array = countersList.map((r) => parseTXT(r));
return array;
const countersListHTML = recursiveFilesSearch({
dir: staticPath,
fileList: [],
filename: 'index.html'
});

const arrayOfLocal = countersListHTML
.filter((r) => {
const folder = path.dirname(r);
return (
countersListTXT.find((s) => path.dirname(s) == folder) == null
);
})
.map((r) => ({
name: path.basename(path.dirname(r)),
author: 'local',
resolution: [-2, '400'],
authorlinks: []
}));

const array = countersListTXT.map((r) => parseTXT(r));
return array.concat(arrayOfLocal);
}

export function buildLocalCounters(res: http.ServerResponse, query?: string) {
Expand Down Expand Up @@ -416,3 +453,29 @@ export function buildSettings(res: http.ServerResponse) {
}
);
}

export function buildInstructionLocal(res: http.ServerResponse) {
const pageContent = `<div class="settings">
<h3>How to Add Your Own Counter <a>Locally</a></h3>
<p>
1. <b>Create a new folder</b>:<br>- First, create a <a>new folder</a> inside your static folder.<br><br>
2. <b>Move your pp counter files</b>:<br>- Next, move <a>your pp counter</a> files into the newly created folder.<br><br>
3. <b>Download and place metadata file</b>:<br>- Download the <a
href="https://raw.githubusercontent.com/cyperdark/osu-counters/master/quickstart/metadata.txt"
target="_blank">metadata.txt</a> file and place it in the counter folder.<br><br>
4. <b>Fill out the metadata file</b>:<br>- Finally, <a>open</a> the metadata.txt file and <a>fill out</a> the necessary information.
</p>
</div>`;
fs.readFile(
'F:/coding/wip/tosu/packages/server/assets/homepage.html',
'utf8',
(err, content) => {
const html = content.replace('{{LIST}}', pageContent);

res.writeHead(200, {
'Content-Type': getContentType('file.html')
});
res.end(html);
}
);
}

0 comments on commit 59c1741

Please sign in to comment.