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

Commit

Permalink
check size
Browse files Browse the repository at this point in the history
  • Loading branch information
k03mad committed Dec 3, 2023
1 parent 154a54c commit 0f0c9ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/cron/task/helpers/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export const getProvidersData = async providers => {
*/
export const downloadApkFile = async ({extraDir = '', homepage, link, opts}) => {
const downloadedApkPath = await retry(
() => download(link, {...opts, ext: 'apk', dir: path.join(serverConfig.static.apk, extraDir)}),
() => download(link, {
...opts,
ext: 'apk',
dir: path.join(serverConfig.static.apk, extraDir),
}),
);

const info = await getApkFileInfo(downloadedApkPath);
Expand Down
5 changes: 4 additions & 1 deletion app/cron/task/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export default async providers => {
const apk = await downloadApkFile({...providerData, extraDir: String(counter)});
debug.extend('finished')(...debugOpts);

if (!apk.fileName?.endsWith('.apk')) {
if (
!apk.fileName?.endsWith('.apk')
|| apk.size.raw < 51_200
) {
throw new Error('Downloaded not apk file');
}

Expand Down
12 changes: 8 additions & 4 deletions utils/aapt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {run} from './shell.js';
* @param {string} apkFilePath
*/
export const getApkFileInfo = async apkFilePath => {
let aapt, date, size;
let aapt, date, size,stat;

try {
aapt = await run(`aapt dump badging ${apkFilePath}`);
Expand All @@ -19,17 +19,21 @@ export const getApkFileInfo = async apkFilePath => {
}

try {
const stat = await fs.stat(apkFilePath);
stat = await fs.stat(apkFilePath);
const [value, unit] = prettyBytes(stat.size, {maximumFractionDigits: 0}).split(' ');

size = {value, unit, raw: stat.size};
} catch (err) {
logError(err);
}

try {
const remoteDate = new Date(stat.mtime).toLocaleDateString();
const currentDate = new Date().toLocaleDateString();

if (remoteDate !== currentDate) {
date = remoteDate;
}

size = {value, unit};
} catch (err) {
logError(err);
}
Expand Down

0 comments on commit 0f0c9ee

Please sign in to comment.