All checks were successful
CI / container-job (push) Successful in 41s
- adonisrc.ts: Load official drive_provider and unload custom driver_provider. - packages.json: Add @headlessui/vue dependency for tab components. - AvatarController.ts: Rewrite avatar generation logic to always return the same avatar per user. - auth/UserController.ts: Add profile and profileUpdate methods to support user profile editing. - Submitter/datasetController.ts & app/models/file.ts: Adapt code to use the official drive_provider. - app/models/user.ts: Introduce “isAdmin” getter. - config/drive.ts: Create new configuration for the official drive_provider. - providers/vinejs_provider.ts: Adapt allowedExtensions control to use provided options or database enabled extensions. - resource/js/app.ts: Load default Head and Link components. - resources/js/menu.ts: Add settings-profile.edit menu point. - resources/js/Components/action-message.vue: Add new component for improved user feedback after form submissions. - New avatar-input.vue component: Enable profile picture selection. - Components/CardBox.vue: Alter layout to optionally show HeaderIcon in title bar. - FormControl.vue: Define a readonly prop for textareas. - Improve overall UI with updates to NavBar.vue, UserAvatar.vue, UserAvatarCurrentUser.vue, and add v-model support to password-meter.vue. - Remove profile editing logic from AccountInfo.vue and introduce new profile components (show.vue, update-password-form.vue, update-profile-information.vue). - app.edge: Modify page (add @inertiaHead tag) for better meta management. - routes.ts: Add new routes for editing user profiles. - General npm updates.
194 lines
6.7 KiB
TypeScript
194 lines
6.7 KiB
TypeScript
/*
|
|
|--------------------------------------------------------------------------
|
|
| Provider File - node ace make:provider vinejsProvider
|
|
|--------------------------------------------------------------------------
|
|
|*/
|
|
import type { ApplicationService } from '@adonisjs/core/types';
|
|
import vine, { symbols, BaseLiteralType, Vine } from '@vinejs/vine';
|
|
import type { FieldContext, FieldOptions } from '@vinejs/vine/types';
|
|
// import type { MultipartFile, FileValidationOptions } from '@adonisjs/bodyparser/types';
|
|
import type { MultipartFile } from '@adonisjs/core/bodyparser';
|
|
import type { FileValidationOptions } from '@adonisjs/core/types/bodyparser';
|
|
import { Request, RequestValidator } from '@adonisjs/core/http';
|
|
import MimeType from '#models/mime_type';
|
|
|
|
|
|
/**
|
|
* Validation options accepted by the "file" rule
|
|
*/
|
|
export type FileRuleValidationOptions = Partial<FileValidationOptions> | ((field: FieldContext) => Partial<FileValidationOptions>);
|
|
/**
|
|
* Extend VineJS
|
|
*/
|
|
declare module '@vinejs/vine' {
|
|
interface Vine {
|
|
myfile(options?: FileRuleValidationOptions): VineMultipartFile;
|
|
}
|
|
}
|
|
/**
|
|
* Extend HTTP request class
|
|
*/
|
|
declare module '@adonisjs/core/http' {
|
|
interface Request extends RequestValidator {}
|
|
}
|
|
|
|
/**
|
|
* Checks if the value is an instance of multipart file
|
|
* from bodyparser.
|
|
*/
|
|
export function isBodyParserFile(file: MultipartFile | unknown): boolean {
|
|
return !!(file && typeof file === 'object' && 'isMultipartFile' in file);
|
|
}
|
|
export async function getEnabledExtensions() {
|
|
const enabledExtensions = await MimeType.query().select('file_extension').where('enabled', true).exec();
|
|
const extensions = enabledExtensions
|
|
.map((extension) => {
|
|
return extension.file_extension.split('|');
|
|
})
|
|
.flat();
|
|
|
|
return extensions;
|
|
}
|
|
/**
|
|
* VineJS validation rule that validates the file to be an
|
|
* instance of BodyParser MultipartFile class.
|
|
*/
|
|
const isMultipartFile = vine.createRule(async (file: MultipartFile | unknown, options: FileRuleValidationOptions, field: FieldContext) => {
|
|
/**
|
|
* Report error when value is not a field multipart
|
|
* file object
|
|
*/
|
|
if (!isBodyParserFile(file)) {
|
|
field.report('The {{ field }} must be a file', 'file', field);
|
|
return;
|
|
}
|
|
// At this point, you can use type assertion to explicitly tell TypeScript that file is of type MultipartFile
|
|
const validatedFile = file as MultipartFile;
|
|
const validationOptions = typeof options === 'function' ? options(field) : options;
|
|
/**
|
|
* Set size when it's defined in the options and missing
|
|
* on the file instance
|
|
*/
|
|
if (validatedFile.sizeLimit === undefined && validationOptions.size) {
|
|
validatedFile.sizeLimit = validationOptions.size;
|
|
}
|
|
/**
|
|
* Set extensions when it's defined in the options and missing
|
|
* on the file instance
|
|
*/
|
|
// if (validatedFile.allowedExtensions === undefined && validationOptions.extnames) {
|
|
// validatedFile.allowedExtensions = validationOptions.extnames;
|
|
// }
|
|
if (validatedFile.allowedExtensions === undefined && validationOptions.extnames !== undefined) {
|
|
validatedFile.allowedExtensions = validationOptions.extnames; // await getEnabledExtensions();
|
|
} else if (validatedFile.allowedExtensions === undefined && validationOptions.extnames === undefined) {
|
|
validatedFile.allowedExtensions = await getEnabledExtensions();
|
|
}
|
|
/**
|
|
* wieder löschen
|
|
* Set extensions when it's defined in the options and missing
|
|
* on the file instance
|
|
*/
|
|
// if (file.clientNameSizeLimit === undefined && validationOptions.clientNameSizeLimit) {
|
|
// file.clientNameSizeLimit = validationOptions.clientNameSizeLimit;
|
|
// }
|
|
/**
|
|
* Validate file
|
|
*/
|
|
validatedFile.validate();
|
|
/**
|
|
* Report errors
|
|
*/
|
|
validatedFile.errors.forEach((error) => {
|
|
field.report(error.message, `file.${error.type}`, field, validationOptions);
|
|
});
|
|
});
|
|
|
|
const MULTIPART_FILE: typeof symbols.SUBTYPE = symbols.SUBTYPE;
|
|
|
|
export class VineMultipartFile extends BaseLiteralType<MultipartFile, MultipartFile, MultipartFile> {
|
|
|
|
[MULTIPART_FILE]: string;
|
|
// constructor(validationOptions?: FileRuleValidationOptions, options?: FieldOptions) {
|
|
// super(options, [isMultipartFile(validationOptions || {})]);
|
|
// this.validationOptions = validationOptions;
|
|
// this.#private = true;
|
|
// }
|
|
|
|
// clone(): this {
|
|
// return new VineMultipartFile(this.validationOptions, this.cloneOptions()) as this;
|
|
// }
|
|
// #private;
|
|
// constructor(validationOptions?: FileRuleValidationOptions, options?: FieldOptions, validations?: Validation<any>[]);
|
|
// clone(): this;
|
|
|
|
public validationOptions;
|
|
// extnames: (18) ['gpkg', 'htm', 'html', 'csv', 'txt', 'asc', 'c', 'cc', 'h', 'srt', 'tiff', 'pdf', 'png', 'zip', 'jpg', 'jpeg', 'jpe', 'xlsx']
|
|
// size: '512mb'
|
|
|
|
// public constructor(validationOptions?: FileRuleValidationOptions, options?: FieldOptions, validations?: Validation<any>[]) {
|
|
public constructor(validationOptions?: FileRuleValidationOptions, options?: FieldOptions) {
|
|
// super(options, validations);
|
|
super(options, [isMultipartFile(validationOptions || {})]);
|
|
this.validationOptions = validationOptions;
|
|
}
|
|
|
|
public clone(): any {
|
|
// return new VineMultipartFile(this.validationOptions, this.cloneOptions(), this.cloneValidations());
|
|
return new VineMultipartFile(this.validationOptions, this.cloneOptions());
|
|
}
|
|
}
|
|
|
|
export default class VinejsProvider {
|
|
protected app: ApplicationService;
|
|
|
|
constructor(app: ApplicationService) {
|
|
this.app = app;
|
|
this.app.usingVineJS = true;
|
|
}
|
|
|
|
/**
|
|
* Register bindings to the container
|
|
*/
|
|
register() {}
|
|
|
|
/**
|
|
* The container bindings have booted
|
|
*/
|
|
|
|
boot(): void {
|
|
// VineString.macro('translatedLanguage', function (this: VineString, options: Options) {
|
|
// return this.use(translatedLanguageRule(options));
|
|
// });
|
|
|
|
Vine.macro('myfile', function (this: Vine, options) {
|
|
return new VineMultipartFile(options);
|
|
});
|
|
|
|
/**
|
|
* The validate method can be used to validate the request
|
|
* data for the current request using VineJS validators
|
|
*/
|
|
Request.macro('validateUsing', function (this: Request, ...args) {
|
|
if (!this.ctx) {
|
|
throw new Error('HttpContext is not available');
|
|
}
|
|
return new RequestValidator(this.ctx).validateUsing(...args);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* The application has been booted
|
|
*/
|
|
async start() {}
|
|
|
|
/**
|
|
* The process has been started
|
|
*/
|
|
async ready() {}
|
|
|
|
/**
|
|
* Preparing to shutdown the app
|
|
*/
|
|
async shutdown() {}
|
|
}
|