This commit introduces the following key features: - **New `.gitignore`**: - Ignores `.vscode`, `.eslintrc.js`, and `dist/module.zip`. - **Core functionality**: - Created `src/main.js` to implement the `AscAssetManager` class with methods to manage file uploads, categories, tags, and settings registration. - Introduced hooks for rendering and managing custom upload dialogs and forms. - **Configuration and settings**: - Added `src/settings.js` to register settings for features like enabling/disabling, root directory configuration, and theme selection. - **Templates**: - Added `upload-choose.hbs` for the file selection dialog. - Added `upload-form.hbs` for the file metadata customization dialog. - **Utilities**: - Added `src/utils.js` with helper functions for file parsing, metadata handling, and filename creation. - **Styling**: - Added `style.css` for styling upload areas. - **Module metadata**: - Added `module.json` with module details, compatibility, and dependencies. This commit establishes the foundational structure and functionality for the AscAssetManager module.
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
export function getFileExtension (fileName) {
|
|
const regex = new RegExp('[^.]+$');
|
|
return fileName.match(regex)?.[0];
|
|
}
|
|
export function getFileBasename (fileName) {
|
|
const regex = new RegExp('^[^.]+');
|
|
return fileName.match(regex)?.[0]
|
|
}
|
|
|
|
export function parseFileName (s) {
|
|
const pattern = /(?<base>^.+)\.(?<extension>[^.]+?$)/
|
|
const match = s.match(pattern)
|
|
if (match && match.groups){
|
|
return {
|
|
fileName: match.groups.base,
|
|
fileExtension: match.groups.extension,
|
|
}
|
|
} else {
|
|
return {fileName: s}
|
|
}
|
|
}
|
|
|
|
const createFileNameDefaultOptions = {
|
|
meta_separator : "__",
|
|
category_prefix : "",
|
|
tag_prefix: "<>",
|
|
tag_separator: "",
|
|
lowerCase: true,
|
|
noSymbols: true,
|
|
}
|
|
|
|
export function createMetaFileName(originalFileName, meta={category:"", tags:[]}, options) {
|
|
const {
|
|
meta_separator,
|
|
category_prefix,
|
|
tag_prefix,
|
|
tag_separator,
|
|
lowerCase,
|
|
noSymbols
|
|
} = {...createFileNameDefaultOptions,...options}
|
|
|
|
let {fileName, fileExtension} = parseFileName(originalFileName)
|
|
|
|
const category_string = `${category_prefix}${meta.category}`
|
|
const tag_string = `${meta.tags.map(tag=>tag_prefix+tag).join('')}`
|
|
|
|
fileName = `${fileName}${meta_separator}${category_string}${tag_separator}${tag_string}`
|
|
|
|
if (lowerCase) {
|
|
fileName = fileName.toLowerCase()
|
|
}
|
|
|
|
if (noSymbols) {
|
|
fileName = fileName.replace(/[^a-z0-9_-]/g,'-')
|
|
}
|
|
|
|
return `${fileName}.${fileExtension}`
|
|
} |