89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
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, pluginRoute = env.TWTKPR_PLUGIN_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 ?? {};
|
|
return {
|
|
// secrets cannot be provided through configuration file, must use ENV / .env
|
|
accessSecret: env.TWTKPR_ACCESS_SECRET,
|
|
refreshSecret: env.TWTKPR_REFRESH_SECRET,
|
|
mainRoute,
|
|
pluginRoute,
|
|
privateDirectory,
|
|
publicDirectory,
|
|
twtxtFilename,
|
|
plugins: {
|
|
...(initialConfiguration?.plugins ?? {}),
|
|
},
|
|
postLimiterConfiguration: {
|
|
active: postLimiterActive,
|
|
...(otherPostLimiterProps ?? {}),
|
|
},
|
|
queryParameters: {
|
|
...queryParameters,
|
|
app,
|
|
css,
|
|
following,
|
|
js,
|
|
logout,
|
|
metadata,
|
|
twt,
|
|
twts,
|
|
},
|
|
};
|
|
}
|
|
//# sourceMappingURL=getConfiguration.js.map
|