Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
update download paths
Browse files Browse the repository at this point in the history
  • Loading branch information
k03mad committed Dec 3, 2023
1 parent 3c8832e commit 154a54c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
— GITHUB_AAPKS_TOKEN: `personal access token`, для приложений с GitHub\
— ARIA_AAPKS_PROXY: добавляет в `aria2c` аргумент `--all-proxy` с содержимым переменной

### Старт
### Запуск

```bash
# предварительно скачать апк-файлы
# только при первом запуске, далее будут скачиваться по крону
npm run apk:dl

# старт сервера
npm run start --port=3030
open http://localhost:3030/apps
```
Expand Down
2 changes: 1 addition & 1 deletion app/cron/scripts/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (env.scripts.provider) {
}

if (env.scripts.type === 'dl') {
await task(providers, env.scripts.skipClean);
await task(providers);
} else {
const providersData = await getProvidersData(providers);
log(providersData);
Expand Down
7 changes: 5 additions & 2 deletions app/cron/task/helpers/fetch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'node:path'

import _ from 'lodash';

import {getApkFileInfo} from '../../../../utils/aapt.js';
Expand Down Expand Up @@ -31,11 +33,12 @@ export const getProvidersData = async providers => {
* @param {object} apk
* @param {string} apk.link
* @param {object} apk.opts
* @param {string} apk.extraDir
* @param {string} apk.homepage
*/
export const downloadApkFile = async ({homepage, link, opts}) => {
export const downloadApkFile = async ({extraDir = '', homepage, link, opts}) => {
const downloadedApkPath = await retry(
() => download(link, {...opts, ext: 'apk', dir: serverConfig.static.apk}),
() => download(link, {...opts, ext: 'apk', dir: path.join(serverConfig.static.apk, extraDir)}),
);

const info = await getApkFileInfo(downloadedApkPath);
Expand Down
19 changes: 8 additions & 11 deletions app/cron/task/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,32 @@ const debug = _debug('mad:task');

/**
* @param {object} providers
* @param {boolean} skipClean
*/
export default async (providers, skipClean) => {
export default async providers => {
const startDate = new Date();
const providersData = await getProvidersData(providers);

if (!skipClean) {
await fs.rm(serverConfig.static.apk, {force: true, recursive: true});
}

const json = {
apk: {},
errors: [],
};

let counter = 0;
const [providersData] = await Promise.all([
getProvidersData(providers),
fs.rm(serverConfig.static.apk, {force: true, recursive: true}),
])

await pMap(
_.shuffle(providersData),

async providerData => {
async (providerData, counter) => {
try {
counter++;
counter++

const {link, providerName} = providerData;

const debugOpts = ['[%o/%o] %o', counter, providersData.length, link];
debug.extend('started')(...debugOpts);
const apk = await downloadApkFile(providerData);
const apk = await downloadApkFile({...providerData, extraDir: String(counter)});
debug.extend('finished')(...debugOpts);

if (!apk.fileName?.endsWith('.apk')) {
Expand Down
14 changes: 9 additions & 5 deletions app/server/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
}

:root {
--font: 10px;
--fontBig: 12px;
--font: 12px;
--fontSmall: 10px;

--black: #19181D;
--magenta: #956485;
Expand All @@ -23,6 +23,7 @@ html {
font-family: Fira, monospace;
font-size: var(--font);
background: var(--black);
white-space: nowrap;
}

a {
Expand All @@ -39,17 +40,15 @@ table {
}

table .provider {
font-size: var(--fontBig);
color: var(--magenta);
}

table .label {
font-size: var(--fontBig);
color: var(--green);
}

table .version {
color: var(--greenDark);
color: var(--green);
}

table .version[title] {
Expand All @@ -65,13 +64,18 @@ table .size {
}

table .main_link {
font-size: var(--fontSmall);
border-bottom: 1px solid var(--blueDark);
}

table .main_link a {
color: var(--blue);
}

table .extra_link {
font-size: var(--fontSmall);
}

.raw {
display: none;
}
Expand Down
7 changes: 6 additions & 1 deletion app/server/views/apps.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
</td>

<td class="extra_link">
{{#if this.homepage}}<a href="{{this.homepage}}" title="home page">[hp]</a>{{/if}}&#8239;{{#if this.relativeDownloadLink}}<a href="{{this.relativeDownloadLink}}" title="apk mirror">[am]</a>{{/if}}
{{#if this.homepage}}
<a href="{{this.homepage}}" title="home page">hp</a>
{{/if}}
{{#if this.relativeDownloadLink}}
<a href="{{this.relativeDownloadLink}}" title="apk mirror">am</a>
{{/if}}
</td>
</tr>
{{/each}}
Expand Down
1 change: 0 additions & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const env = {
debug: process.env.DEBUG,
scripts: {
provider: process.env.npm_config_provider,
skipClean: process.env.npm_config_skip_clean,
type: process.env.TYPE,
},
github: {
Expand Down

0 comments on commit 154a54c

Please sign in to comment.