mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Replace linting configurations
The previous package was outdated, preventing us from updating TS. This one also lints YAML and JSON, and applies many more rules to the test files, explaining all the changes in this PR.
This commit is contained in:
@@ -4,7 +4,8 @@ import type { HttpHandlerInput } from '../HttpHandler';
|
||||
import { HttpHandler } from '../HttpHandler';
|
||||
|
||||
const defaultOptions: CorsOptions = {
|
||||
origin: (origin: any, callback: any): void => callback(null, origin ?? '*'),
|
||||
origin: (origin: string | undefined, callback: (err: Error | null, origin?: string) => void): void =>
|
||||
callback(null, origin ?? '*'),
|
||||
};
|
||||
|
||||
// Components.js does not support the full CorsOptions yet
|
||||
@@ -47,7 +48,7 @@ export class CorsHandler extends HttpHandler {
|
||||
|
||||
public async handle(input: HttpHandlerInput): Promise<void> {
|
||||
return new Promise((resolve): void => {
|
||||
this.corsHandler(input.request as any, input.response as any, (): void => resolve());
|
||||
this.corsHandler(input.request, input.response, (): void => resolve());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { APPLICATION_OCTET_STREAM } from '../../util/ContentTypes';
|
||||
import { InternalServerError } from '../../util/errors/InternalServerError';
|
||||
import { NotFoundHttpError } from '../../util/errors/NotFoundHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import type { SystemError } from '../../util/errors/SystemError';
|
||||
import { ensureTrailingSlash, joinFilePath, resolveAssetPath, trimLeadingSlashes } from '../../util/PathUtil';
|
||||
import { pipeSafely } from '../../util/StreamUtil';
|
||||
import type { HttpHandlerInput } from '../HttpHandler';
|
||||
@@ -40,7 +41,8 @@ export class StaticAssetHandler extends HttpHandler {
|
||||
* Creates a handler for the provided static resources.
|
||||
* @param assets - A list of {@link StaticAssetEntry}.
|
||||
* @param baseUrl - The base URL of the server.
|
||||
* @param options - Cache expiration time in seconds.
|
||||
* @param options - Specific options.
|
||||
* @param options.expires - Cache expiration time in seconds.
|
||||
*/
|
||||
public constructor(assets: StaticAssetEntry[], baseUrl: string, options: { expires?: number } = {}) {
|
||||
super();
|
||||
@@ -118,6 +120,7 @@ export class StaticAssetHandler extends HttpHandler {
|
||||
asset.once('readable', (): void => {
|
||||
const contentType = mime.lookup(filePath) || APPLICATION_OCTET_STREAM;
|
||||
response.writeHead(200, {
|
||||
// eslint-disable-next-line ts/naming-convention
|
||||
'content-type': contentType,
|
||||
...this.getCacheHeaders(),
|
||||
});
|
||||
@@ -135,7 +138,7 @@ export class StaticAssetHandler extends HttpHandler {
|
||||
|
||||
// Pass the error when something goes wrong
|
||||
asset.once('error', (error): void => {
|
||||
const { code } = error as any;
|
||||
const { code } = error as SystemError;
|
||||
// When the file if not found or a folder, signal a 404
|
||||
if (code === 'ENOENT' || code === 'EISDIR') {
|
||||
this.logger.debug(`Static asset ${filePath} not found`);
|
||||
@@ -153,10 +156,11 @@ export class StaticAssetHandler extends HttpHandler {
|
||||
|
||||
private getCacheHeaders(): Record<string, string> {
|
||||
return this.expires <= 0 ?
|
||||
{} :
|
||||
{
|
||||
'cache-control': `max-age=${this.expires}`,
|
||||
expires: new Date(Date.now() + (this.expires * 1000)).toUTCString(),
|
||||
};
|
||||
{} :
|
||||
{
|
||||
// eslint-disable-next-line ts/naming-convention
|
||||
'cache-control': `max-age=${this.expires}`,
|
||||
expires: new Date(Date.now() + (this.expires * 1000)).toUTCString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user