Switch to new swaf logger
This commit is contained in:
parent
6a2931e699
commit
6d34829263
@ -2,13 +2,13 @@ import Controller from "swaf/Controller";
|
|||||||
import {NextFunction, Request, Response} from "express";
|
import {NextFunction, Request, Response} from "express";
|
||||||
import * as https from "https";
|
import * as https from "https";
|
||||||
import config from "config";
|
import config from "config";
|
||||||
import {log} from "swaf/Logger";
|
|
||||||
import {NotFoundHttpError, ServiceUnavailableHttpError} from "swaf/HttpError";
|
import {NotFoundHttpError, ServiceUnavailableHttpError} from "swaf/HttpError";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import {promisify} from "util";
|
import {promisify} from "util";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import sendRanges, {SendRangeGetStreamFn} from "send-ranges";
|
import sendRanges, {SendRangeGetStreamFn} from "send-ranges";
|
||||||
import mime from "mime";
|
import mime from "mime";
|
||||||
|
import {logger} from "swaf/Logger";
|
||||||
|
|
||||||
export const ASSETS_BASE_DIR = config.get<string>('assets_base_dir');
|
export const ASSETS_BASE_DIR = config.get<string>('assets_base_dir');
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ export default class GiteaRepoLatestReleaseController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async getFile(req: Request, res: Response, next: NextFunction): Promise<void> {
|
protected async getFile(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||||
log.info('Serving ' + req.path + ' ...');
|
logger.info('Serving ' + req.path + ' ...');
|
||||||
const {owner, name, file} = req.params;
|
const {owner, name, file} = req.params;
|
||||||
if (!owner || !name) return next();
|
if (!owner || !name) return next();
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ export default class GiteaRepoLatestReleaseController extends Controller {
|
|||||||
for (const release of releases) {
|
for (const release of releases) {
|
||||||
for (const asset of release.assets) {
|
for (const asset of release.assets) {
|
||||||
if (asset.name === file) {
|
if (asset.name === file) {
|
||||||
log.debug('Download', asset.browser_download_url);
|
logger.debug('Download', asset.browser_download_url);
|
||||||
return await this.download(req, res, next, {
|
return await this.download(req, res, next, {
|
||||||
repo: {
|
repo: {
|
||||||
owner: owner,
|
owner: owner,
|
||||||
@ -57,7 +57,7 @@ export default class GiteaRepoLatestReleaseController extends Controller {
|
|||||||
}
|
}
|
||||||
throw new NotFoundHttpError('Asset', req.url);
|
throw new NotFoundHttpError('Asset', req.url);
|
||||||
} else {
|
} else {
|
||||||
log.debug('List files');
|
logger.debug('List files');
|
||||||
return res.render('list-files', {
|
return res.render('list-files', {
|
||||||
owner: owner,
|
owner: owner,
|
||||||
name: name,
|
name: name,
|
||||||
@ -70,7 +70,7 @@ export default class GiteaRepoLatestReleaseController extends Controller {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
httpRequest.on('error', err => {
|
httpRequest.on('error', err => {
|
||||||
log.error(err);
|
logger.error(err);
|
||||||
});
|
});
|
||||||
httpRequest.end();
|
httpRequest.end();
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ export default class GiteaRepoLatestReleaseController extends Controller {
|
|||||||
await promisify(fs.rename)(tmpAssetPath, assetPath);
|
await promisify(fs.rename)(tmpAssetPath, assetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug('Download', assetPath, downloadProperties.asset.name);
|
logger.debug('Download', assetPath, downloadProperties.asset.name);
|
||||||
|
|
||||||
sendRanges(async _ => {
|
sendRanges(async _ => {
|
||||||
const filePath = assetPath;
|
const filePath = assetPath;
|
||||||
@ -126,7 +126,7 @@ export default class GiteaRepoLatestReleaseController extends Controller {
|
|||||||
})(req, res, (err: unknown) => {
|
})(req, res, (err: unknown) => {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
|
|
||||||
log.info('Fallback to express download.');
|
logger.info('Fallback to express download.');
|
||||||
|
|
||||||
// Respond
|
// Respond
|
||||||
return res.download(assetPath, downloadProperties.asset.name);
|
return res.download(assetPath, downloadProperties.asset.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user