actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
60 lines (59 loc) • 2.35 kB
TypeScript
import * as fs from "fs";
import { Initializer } from "../index";
import { Connection } from "./../classes/connection";
export interface StaticFileApi {
searchLocations: Array<string>;
get?: StaticFileInitializer["get"];
sendFile?: StaticFileInitializer["sendFile"];
searchPath?: StaticFileInitializer["searchPath"];
checkExistence?: StaticFileInitializer["checkExistence"];
sendFileNotFound?: StaticFileInitializer["sendFileNotFound"];
logRequest?: StaticFileInitializer["logRequest"];
fileLogger?: StaticFileInitializer["fileLogger"];
}
/**
* Contains helpers for returning flies to connections.
*/
export declare class StaticFileInitializer extends Initializer {
constructor();
/**
* For a connection with `connection.params.file` set, return a file if we can find it, or a not-found message.
* `searchLocations` will be checked in the following order: first paths in this project, then plugins.
* This can be used in Actions to return files to clients. If done, set `data.toRender = false` within the action.
* return is of the form: {connection, error, fileStream, mime, length}
*/
get: (connection: Connection, counter?: number) => Promise<{
connection: Connection;
error?: any;
mime: string;
length: any;
fileStream?: fs.ReadStream;
lastModified?: Date;
}>;
searchPath: (counter?: number) => string;
sendFile: (file: string, connection: Connection) => Promise<{
connection: Connection;
error: string;
mime: string;
length: number;
} | {
connection: Connection;
fileStream: fs.ReadStream;
mime: string;
length: number | bigint;
lastModified: Date;
}>;
fileLogger: (fileStream: any, connection: Connection, start: number, file: string, length: number | bigint) => void;
sendFileNotFound: (connection: Connection, errorMessage: string) => Promise<{
connection: Connection;
error: string;
mime: string;
length: number;
}>;
checkExistence: (file: string) => Promise<{
exists: boolean;
truePath: string;
}>;
logRequest: (file: string, connection: Connection, length: number | bigint, duration: number, success: boolean) => void;
initialize(): Promise<void>;
}