feat: update to vite.js, Refactor configuration files, remove unused assets, and clean up commented code:
All checks were successful
CI / container-job (push) Successful in 43s

- ace.js: use ts-node-maintained
- adonisrc.ts: load vite_provider, sett assetBundler to false, addd hooks property
- Dockerfile: change to node version 22
- package.json: remove babel depencies; add @swc/wasm, add vitejs/plugin-vue, add hot-hook, add vite,  update eslint-config-prettier, tailwindcss, ts-node-maintained
- new vite.config.js and config/vite.ts
- inertia.js
- improved own vinejs_provider.ts
- adapted app.css needed for vitejs
- adapted app.ts: new resolve method neede for vitejs
relocated resources/js/logo.svg
- remove Buffer import into FileUpload.vue
- Create.vue: improved submit needed for @inertiajs/vue3 form helper
- Edit.vue: mproved submit needed for @inertiajs/vue3 form helper
- kernel.ts: load vite_middleware
- formated rotes.ts file
- rewritten allowed_extensions_mimetypes.ts file (removed typescript errors)
This commit is contained in:
Kaimbacher 2025-02-07 10:14:57 +01:00
parent 8d47a58d29
commit 4c5a8f5a42
40 changed files with 1647 additions and 4926 deletions

View file

@ -9,7 +9,6 @@ import vine from '@vinejs/vine';
// import { VineString } from '@vinejs/vine';
import { VineMultipartFile, isBodyParserFile } from '#providers/vinejs_provider';
import type { MultipartFile } from '@adonisjs/core/bodyparser';
// import db from '@adonisjs/lucid/services/db';
import MimeType from '#models/mime_type';
/**
@ -22,11 +21,14 @@ import MimeType from '#models/mime_type';
type Options = {
// size: string | number;
// extnames: string[];
clientNameSizeLimit: number;
// clientNameSizeLimit?: number;
allowedExtensions: string[];
allowedMimeTypes: string[];
};
// async function allowedMimetypeExtensions(file: VineMultipartFile | unknown, options: Options | unknown, field: FieldContext) {
async function allowedMimetypeExtensions(file: VineMultipartFile | unknown, options: Options | unknown, field: FieldContext) {
async function allowedMimetypeExtensions(file: VineMultipartFile | unknown, options: Options, field: FieldContext) {
// if (typeof value !== 'string' && typeof value != 'number') {
// return;
// }
@ -42,7 +44,7 @@ async function allowedMimetypeExtensions(file: VineMultipartFile | unknown, opti
const mimeRecord = await MimeType.query().select('file_extension').where('name', mimeType).andWhere('enabled', true).first();
if (!mimeRecord) {
const allowedMimetypes = await MimeType.query().select('name').where('enabled', true);
const allowedMimetypes = await MimeType.query().select('name').where('enabled', true)
// Transform allowed MIME types to a concatenated string
const allowedMimetypesString = allowedMimetypes.map((mime) => mime.name).join(', ');
// throw new Error('Invalid MIME type');
@ -53,14 +55,19 @@ async function allowedMimetypeExtensions(file: VineMultipartFile | unknown, opti
field,
);
} else {
const allowedExtensions = mimeRecord.file_extension.split('|');
let allowedExtensions: string[] = [];
if (options && options.allowedExtensions) {
allowedExtensions = options.allowedExtensions;
} else {
allowedExtensions = mimeRecord.file_extension.split('|');
}
// Validate if the file's extension is in the allowed extensions
if (!allowedExtensions.includes(fileExtension)) {
//throw new Error(`File extension ${fileExtension} is not allowed for MIME type ${mimeType}`);
field.report(
`File extension ${fileExtension} is not allowed for MIME type ${mimeType}. Allowed extensions are: ${mimeRecord.file_extension}`,
'allowedMimetypeExtensions',
field
'allowedMimetypeExtensions',
field,
);
}
// if (validatedFile.clientName.length > options.clientNameSizeLimit) {
@ -74,10 +81,10 @@ export const allowedMimetypeExtensionsRule = vine.createRule(allowedMimetypeExte
declare module '#providers/vinejs_provider' {
interface VineMultipartFile {
allowedMimetypeExtensions(options?: Options): this;
allowedMimetypeExtensions(options?: Options): this;
}
}
VineMultipartFile.macro('allowedMimetypeExtensions', function (this: VineMultipartFile, options: Options) {
return this.use(allowedMimetypeExtensionsRule(options));
return this.use(allowedMimetypeExtensionsRule(options));
});

View file

@ -1,7 +1,7 @@
import { FieldContext } from '@vinejs/vine/types';
import vine from '@vinejs/vine';
import { VineString } from '@vinejs/vine';
import axios from 'axios';
import { default as axios } from 'axios';
import { ReferenceIdentifierTypes } from '#contracts/enums';
type Options = {
@ -11,7 +11,7 @@ type Options = {
// Function to check if DOI exists using the DOI API
async function checkDoiExists(doi: string): Promise<boolean> {
try {
const response = await axios.default.get(`${doi}`);
const response = await axios.get(`${doi}`);
return response.status === 200; // If status is 200, DOI is valid
} catch (error) {
return false; // If request fails, DOI does not exist
@ -21,7 +21,7 @@ async function checkDoiExists(doi: string): Promise<boolean> {
// Function to check if ISBN exists using the Open Library API
async function checkIsbnExists(isbn: string): Promise<boolean> {
try {
const response = await axios.default.get(`https://isbnsearch.org/isbn/${isbn}`);
const response = await axios.get(`https://isbnsearch.org/isbn/${isbn}`);
return response.data && response.status == 200; // If title is returned, ISBN is valid
} catch (error) {
return false; // If request fails, ISBN does not exist

View file

@ -17,7 +17,7 @@ type Options = {
};
async function translatedLanguage(value: unknown, options: Options, field: FieldContext) {
if (typeof value !== 'string' && typeof value != 'number') {
if (typeof value !== 'string' && typeof value !== 'number') {
return;
}

View file

@ -15,11 +15,11 @@ import { VineString, VineNumber } from '@vinejs/vine';
type Options = {
table: string;
column: string;
whereNot?: ((field: FieldContext) => string);
whereNot?: (field: FieldContext) => string;
};
async function isUnique(value: unknown, options: Options, field: FieldContext) {
if (typeof value !== 'string' && typeof value != 'number') {
if (typeof value !== 'string' && typeof value !== 'number') {
return;
}
@ -37,13 +37,11 @@ async function isUnique(value: unknown, options: Options, field: FieldContext) {
// report that value is NOT unique
field.report('The {{ field }} field is not unique', 'isUnique', field);
// field.report(messages.unique, "isUnique", field);
}
}
}
export const isUniqueRule = vine.createRule(isUnique);
declare module '@vinejs/vine' {
interface VineString {
isUnique(options: Options): this;
@ -58,4 +56,4 @@ VineString.macro('isUnique', function (this: VineString, options: Options) {
});
VineNumber.macro('isUnique', function (this: VineNumber, options: Options) {
return this.use(isUniqueRule(options));
});
});

View file

@ -19,9 +19,8 @@ type Options = {
idField: string;
};
async function isUniquePerson(value: unknown, options: Options, field: FieldContext) {
if (typeof value !== 'string' && typeof value != 'number') {
if (typeof value !== 'string' && typeof value !== 'number') {
return;
}
@ -40,13 +39,11 @@ async function isUniquePerson(value: unknown, options: Options, field: FieldCont
if (result) {
// report that value is NOT unique
field.report('The {{ field }} field is not unique', 'isUnique', field);
}
}
}
export const isUniquePersonRule = vine.createRule(isUniquePerson);
declare module '@vinejs/vine' {
interface VineString {
isUniquePerson(options: Options): this;
@ -61,4 +58,4 @@ VineString.macro('isUniquePerson', function (this: VineString, options: Options)
});
VineNumber.macro('isUniquePerson', function (this: VineNumber, options: Options) {
return this.use(isUniquePersonRule(options));
});
});