alpha release
update v0.8.0
This commit is contained in:
103
dist/src/lib/getConfiguration.js
vendored
Normal file
103
dist/src/lib/getConfiguration.js
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
import { env } from './env.js';
|
||||
/**
|
||||
*
|
||||
* @param allowedMimeTypes
|
||||
* @returns
|
||||
*/
|
||||
const getDestinationByMimeTypeConfiguration = (allowedMimeTypes) => {
|
||||
const fallback = {
|
||||
audio: {
|
||||
directory: 'audio',
|
||||
rename: false,
|
||||
},
|
||||
image: {
|
||||
directory: 'images',
|
||||
rename: true,
|
||||
},
|
||||
video: {
|
||||
directory: 'videos',
|
||||
rename: true,
|
||||
},
|
||||
'*': {
|
||||
directory: 'files',
|
||||
rename: false,
|
||||
},
|
||||
};
|
||||
const mimeTypeArrayReducer = (acc, curr) => {
|
||||
if (fallback[curr])
|
||||
acc[curr] = fallback[curr];
|
||||
else
|
||||
acc[curr] = {
|
||||
directory: `${curr}s`,
|
||||
rename: false,
|
||||
};
|
||||
return acc;
|
||||
};
|
||||
if (!allowedMimeTypes)
|
||||
return fallback;
|
||||
if (typeof allowedMimeTypes === 'string')
|
||||
return allowedMimeTypes
|
||||
.split(',')
|
||||
.map((val) => val.trim())
|
||||
.reduce(mimeTypeArrayReducer, {});
|
||||
if (Array.isArray(allowedMimeTypes))
|
||||
return allowedMimeTypes.reduce(mimeTypeArrayReducer, {});
|
||||
if (typeof allowedMimeTypes === 'object')
|
||||
return allowedMimeTypes;
|
||||
return fallback;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @param initialConfiguration
|
||||
* @returns
|
||||
*/
|
||||
export default function getConfiguration(initialConfiguration) {
|
||||
const { mainRoute = env.TWTKPR_DEFAULT_ROUTE, privateDirectory = env.TWTKPR_PRIVATE_DIRECTORY, publicDirectory = env.TWTKPR_PUBLIC_DIRECTORY, twtxtFilename = env.TWTKPR_TWTXT_FILENAME, postLimiterConfiguration, queryParameters, uploadConfiguration, } = initialConfiguration ?? {};
|
||||
const { active: postLimiterActive = env.TWTKPR_POST_LIMITER_ACTIVE, ...otherPostLimiterProps } = postLimiterConfiguration ?? {};
|
||||
const { app = env.TWTKPR_QUERY_PARAMETER_APP, css = env.TWTKPR_QUERY_PARAMETER_CSS, following = env.TWTKPR_QUERY_PARAMETER_FOLLOWING, js = env.TWTKPR_QUERY_PARAMETER_JS, logout = env.TWTKPR_QUERY_PARAMETER_LOGOUT, metadata = env.TWTKPR_QUERY_PARAMETER_METADATA, twt = env.TWTKPR_QUERY_PARAMETER_TWT, twts = env.TWTKPR_QUERY_PARAMETER_TWTS, } = queryParameters ?? {};
|
||||
const { active: uploadActive = env.TWTKPR_UPLOAD_ACTIVE, allowEmptyFiles = env.TWTKPR_UPLOAD_ALLOW_EMPTY_FILES, allowedMimeTypes = env.TWTKPR_UPLOAD_ALLOWED_MIME_TYPES, createDirsFromUploads = env.TWTKPR_UPLOAD_CREATE_DIRS_FROM_UPLOADS, directory = env.TWTKPR_UPLOAD_DIRECTORY, encoding = env.TWTKPR_UPLOAD_ENCODING, fileWriteStreamHandler, filter = () => true, hashAlgorithm = env.TWTKPR_UPLOAD_HASH_ALGORITHM, keepExtensions = env.TWTKPR_UPLOAD_KEEP_EXTENSIONS, maxFields = env.TWTKPR_UPLOAD_MAX_FIELDS, maxFileSize = env.TWTKPR_UPLOAD_MAX_FIELDS_SIZE, maxFiles = env.TWTKPR_UPLOAD_MAX_FILES, maxTotalFileSize = env.TWTKPR_UPLOAD_MAX_TOTAL_FILE_SIZE, minFileSize = env.TWTKPR_UPLOAD_MIN_FILE_SIZE, route = env.TWTKPR_UPLOAD_ROUTE, } = uploadConfiguration ?? {};
|
||||
return {
|
||||
// secrets cannot be provided through configuration file, must use ENV / .env
|
||||
accessSecret: env.TWTKPR_ACCESS_SECRET,
|
||||
refreshSecret: env.TWTKPR_REFRESH_SECRET,
|
||||
mainRoute,
|
||||
privateDirectory,
|
||||
publicDirectory,
|
||||
twtxtFilename,
|
||||
postLimiterConfiguration: {
|
||||
active: postLimiterActive,
|
||||
...(otherPostLimiterProps ?? {}),
|
||||
},
|
||||
queryParameters: {
|
||||
...queryParameters,
|
||||
app,
|
||||
css,
|
||||
following,
|
||||
js,
|
||||
logout,
|
||||
metadata,
|
||||
twt,
|
||||
twts,
|
||||
},
|
||||
uploadConfiguration: {
|
||||
...uploadConfiguration,
|
||||
active: uploadActive,
|
||||
allowEmptyFiles,
|
||||
allowedMimeTypes: getDestinationByMimeTypeConfiguration(allowedMimeTypes),
|
||||
createDirsFromUploads,
|
||||
directory,
|
||||
encoding,
|
||||
fileWriteStreamHandler,
|
||||
filter,
|
||||
hashAlgorithm: hashAlgorithm,
|
||||
keepExtensions,
|
||||
maxFields,
|
||||
maxFileSize,
|
||||
maxFiles,
|
||||
maxTotalFileSize,
|
||||
minFileSize,
|
||||
route,
|
||||
},
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=getConfiguration.js.map
|
||||
Reference in New Issue
Block a user