- npm added @japa/api-client, @japa/assert, @types/supertest
Some checks failed
CI Pipeline / japa-tests (push) Failing after 1m13s

- webpack added opions['__VUE_PROD_HYDRATION_MISMATCH_DETAILS__'] = false;
- bodyparser config replaced whitelistedMethods with allowedMethods
- extended stardust_provider
- adapted tests for adonisjs v6
This commit is contained in:
Kaimbacher 2024-04-25 15:17:22 +02:00
parent 296c8fd46e
commit bee76f8d5b
23 changed files with 2014 additions and 165 deletions

View file

@ -1,21 +1,24 @@
import fsExtra from 'fs-extra'
import fsExtra from 'fs-extra';
// import { RouterContract } from '@ioc:Adonis/Core/Route';
// import { Visibility, DriveFileStats, ContentHeaders, LocalDriverConfig, LocalDriverContract, DirectoryListingContract, LocalDriveListItem } from '@ioc:Adonis/Core/Drive';
import { CannotGetMetaDataException, CannotDeleteFileException, CannotListDirectoryException } from '../exceptions/index.js';
import PathPrefixer from '../path_prefixer/index.js';
import {
LocalDriverContract,
LocalDriverConfig,
DriverContract,
DriveListItem,
} from '../src/types/drive.js';
CannotGetMetaDataException,
CannotDeleteFileException,
CannotListDirectoryException,
CannotMoveFileException,
CannotGenerateUrlException,
} from '../exceptions/index.js';
import PathPrefixer from '../path_prefixer/index.js';
import { LocalDriverContract, LocalDriverConfig, DriverContract, DriveListItem } from '../src/types/drive.js';
import { AsyncIterableArray } from '../src/iterable_array.js';
import router from '@adonisjs/core/services/router'
/**
* Local driver interacts with the local file system
*/
export class LocalDriver implements LocalDriverContract {
private diskName: string;
private routeName: string;
private config;
// private router;
// private routeName;
@ -40,7 +43,7 @@ export class LocalDriver implements LocalDriverContract {
this.diskName = diskName;
this.config = config;
// this.router = router;
// this.routeName = LocalFileServer_1.LocalFileServer.makeRouteName(this.diskName);
this.routeName = ""; //LocalFileServer_1.LocalFileServer.makeRouteName(this.diskName);
/**
* Reference to the underlying adapter. Which is
* fs-extra
@ -56,10 +59,16 @@ export class LocalDriver implements LocalDriverContract {
this.prefixer = PathPrefixer.fromPath(this.config.root); //root: '/storage/app/public',
}
/**
* A boolean to find if the location path exists or not
/**
* Returns a URL for a given location path
*/
exists(location: string): Promise<boolean>;
public async getUrl(location: string) {
if (!this.config.serveFiles) {
throw CannotGenerateUrlException.invoke(location, this.diskName);
}
return router.makeUrl(this.routeName);
}
/**
* A boolean to find if the location path exists or not
*/
@ -90,6 +99,21 @@ export class LocalDriver implements LocalDriverContract {
}
}
public async move(source: string, destination: string): Promise<void> {
try {
let sourcePath = this.makePath(source); //'/storage/app/public/tmp/rtwgliatumwwpd4vpayo4ymg'
let destinationPath = this.makePath(destination);
await this.adapter.move(sourcePath, destinationPath, {
overwrite: true,
});
await this.adapter.move(this.makePath(source), this.makePath(destination), {
overwrite:true
});
} catch (error) {
throw CannotMoveFileException.invoke(source, destination, error);
}
}
/**
* Return a listing directory iterator for given location.
*/
@ -98,7 +122,9 @@ export class LocalDriver implements LocalDriverContract {
const fullPath = this.makePath(location); //'/storage/app/public/files/307'
// let dirListing: DirectoryListing<DriverContract, DriveListItem<any>> = new DirectoryListing(this, () => this.getListing(fullPath, location));
let dirListing: AsyncIterableArray<DriverContract, DriveListItem<any>> = new AsyncIterableArray(this, () => this.getListing(fullPath, location));
let dirListing: AsyncIterableArray<DriverContract, DriveListItem<any>> = new AsyncIterableArray(this, () =>
this.getListing(fullPath, location),
);
return dirListing;
// let listing: DriveListItem<fsExtra.Dirent>[] = await this.getListing(fullPath, location);
// let test = new DirectoryListing(this, listing);
@ -123,7 +149,7 @@ export class LocalDriver implements LocalDriverContract {
location: prefixer.prefixPath(dirent.name),
isFile: dirent.isFile(),
original: dirent,
};
};
}
// return listing;
} catch (error) {

View file

@ -19,7 +19,24 @@ export class CannotDeleteFileException extends Exception {
return error;
}
}
/**
* Unable to move file from source to destination
*/
export class CannotMoveFileException extends Exception {
source: string;
destination: string;
original: any;
static invoke(source: string, destination: string, original: any): CannotMoveFileException {
const error = new this(`Cannot move file from "${source}" to "${destination}"`, {
status: 500,
code: 'E_CANNOT_MOVE_FILE',
});
error.source = source;
error.destination = destination;
error.original = original;
return error;
}
}
/**
* Custom exception for when file metadata cannot be retrieved
*/
@ -71,3 +88,22 @@ export class CannotListDirectoryException extends Exception {
return error;
}
}
/**
* Unable to generate url for a file. The assets serving is disabled
*/
export class CannotGenerateUrlException extends Exception {
location: string;
static invoke(location: string, diskName: string): CannotGenerateUrlException {
const error = new this(
`Cannot generate URL for location "${location}". Make sure to set "serveFiles = true" for "${diskName}" disk`,
{
status: 500,
code: 'E_CANNOT_GENERATE_URL',
},
);
error.location = location;
return error;
}
}

View file

@ -76,9 +76,11 @@ export default class DriveManager extends Manager<
/**
* Make instance of the local driver
*/
protected createLocal(diskName: keyof DriversList, config: LocalDriverConfig) {
// protected createLocal(diskName: keyof DriversList, config: LocalDriverConfig) {
protected createLocal(diskName: keyof DriversList, config: LocalDriverConfig) {
// const { LocalDriver } = await import('../drivers/local.js');
return new LocalDriver(diskName, config);
// return new LocalDriver(config);
}
constructor(application: ApplicationService, config: DriveConfig) {
@ -115,7 +117,7 @@ export default class DriveManager extends Manager<
code: 'E_MISSING_DRIVE_CONFIG',
});
}
disk = disk || this.getDefaultMappingName();
disk = disk || this.getDefaultMappingName(); //#local'
// if (this.fakeDrive.isFaked(disk)) {
// return this.fakeDrive.use(disk);
// }
@ -151,4 +153,21 @@ export default class DriveManager extends Manager<
}
return driver.list(location);
}
/**
* Move a given location path from the source to the desination.
* The missing intermediate directories will be created (if required)
*/
move(source: string, ...args: string[]): Promise<void>{
const driver = this.use();
return driver.move(source, args[0]);
}
/**
* Make absolute path to a given location
*/
public makePath(location: string): string {
const driver = this.use();
return driver.makePath(location);
}
}