feat(core): add provider defaults, strengthen WebDAV validation, and modernize tests and package metadata

This commit is contained in:
2026-05-01 22:31:47 +00:00
parent 157f97cbd7
commit 623788ae25
14 changed files with 8148 additions and 4210 deletions
+25 -13
View File
@@ -9,7 +9,7 @@ export interface IWebdavExposeProviderOptions {
export class WebDavExposeProvider extends ExposeProvider {
public smartExposeRef: SmartExpose;
public webdavClient: plugins.smartwebdav.WebdavClient;
public webdavClient!: plugins.smartwebdav.WebdavClient;
public options: IWebdavExposeProviderOptions;
constructor(smartexposeRefArg: SmartExpose, optionsArg: IWebdavExposeProviderOptions) {
@@ -65,27 +65,37 @@ export class WebDavExposeProvider extends ExposeProvider {
)})`
);
const webdavFilePath = await this.getFilePathById(fileId);
const fileToUpload = await plugins.smartfile.SmartFile.fromBuffer(
webdavFilePath,
optionsArg.smartFile.contents
);
const fileToUpload = new plugins.smartfile.SmartFile({
path: webdavFilePath,
contentBuffer: optionsArg.smartFile.contents,
base: '/',
});
await this.webdavClient.uploadSmartFileArray([fileToUpload]);
console.log(`checking file presence: ${webdavFilePath}`);
const existsOnWebdav = await this.webdavClient.wdClient.exists(webdavFilePath);
if (!existsOnWebdav) {
throw new Error(`Uploaded file does not exist on WebDAV: ${webdavFilePath}`);
}
const publicUrl = plugins.smartpath.join(
this.smartExposeRef.options.exposedBaseUrl,
webdavFilePath
);
console.log(`cehcking for file at ${publicUrl}`);
const response = await plugins.smartrequest.getBinary(publicUrl);
plugins.smartexpect.expect(response.body).toEqual(fileToUpload.contents);
console.log(`checking for file at ${publicUrl}`);
const response = await plugins.smartrequest.SmartRequest.create()
.url(publicUrl)
.accept('binary')
.get();
const responseBuffer = Buffer.from(await response.arrayBuffer());
if (!responseBuffer.equals(fileToUpload.contents)) {
throw new Error(`Public URL did not return the uploaded file contents: ${publicUrl}`);
}
if (optionsArg.deleteAfterMillis) {
console.log(
`Scheduling deletion of file with id: ${fileId} in ${optionsArg.deleteAfterMillis}ms...`
);
plugins.smartdelay.delayFor(optionsArg.deleteAfterMillis).then(() => {
void plugins.smartdelay.delayFor(optionsArg.deleteAfterMillis).then(async () => {
console.log(`Deleting file with id: ${fileId}...`);
this.deleteFileById(fileId);
await this.deleteFileById(fileId);
console.log(`Deleted file with id: ${fileId}`);
});
}
@@ -96,8 +106,10 @@ export class WebDavExposeProvider extends ExposeProvider {
};
}
public async exposeFileArray(optionsArg: Parameters<ExposeProvider['exposeFileArray']>[0]) {
const returnArray = [];
public async exposeFileArray(
optionsArg: Parameters<ExposeProvider['exposeFileArray']>[0]
): ReturnType<ExposeProvider['exposeFileArray']> {
const returnArray: Awaited<ReturnType<ExposeProvider['exposeFile']>>[] = [];
for (const smartFile of optionsArg.smartFiles) {
returnArray.push(
await this.exposeFile({
@@ -125,7 +137,7 @@ export class WebDavExposeProvider extends ExposeProvider {
idArg: string
): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }> {
const filePath = await this.getFilePathById(idArg);
if (!this.webdavClient.wdClient.exists(filePath)) {
if (!(await this.webdavClient.wdClient.exists(filePath))) {
return {
id: idArg,
status: 'notfound',