Compare commits

..

No commits in common. "master" and "v1.0.4" have entirely different histories.

6 changed files with 23 additions and 63 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/smartexpose", "name": "@push.rocks/smartexpose",
"version": "1.0.6", "version": "1.0.4",
"private": false, "private": false,
"description": "a package to expose things to the internet", "description": "a package to expose things to the internet",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -36,12 +36,12 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://code.foss.global/push.rocks/smartexpose.git" "url": "git+https://code.foss.global/push.rocks/smartexpose.git"
}, },
"bugs": { "bugs": {
"url": "https://code.foss.global/push.rocks/smartexpose/issues" "url": "https://code.foss.global/push.rocks/smartexpose/issues"
}, },
"homepage": "https://code.foss.global/push.rocks/smartexpose", "homepage": "https://code.foss.global/push.rocks/smartexpose#readme",
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
], ],

View File

@ -1 +0,0 @@

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartexpose', name: '@push.rocks/smartexpose',
version: '1.0.6', version: '1.0.4',
description: 'a package to expose things to the internet' description: 'a package to expose things to the internet'
} }

View File

@ -28,16 +28,6 @@ export abstract class ExposeProvider {
status: 'created' | 'updated'; status: 'created' | 'updated';
}>; }>;
public abstract exposeFileArray(optionsArg: {
smartFiles: plugins.smartfile.SmartFile[],
deleteAfterMillis?: number,
privateUrl?: boolean,
}): Promise<{
url: string;
id: string;
status: 'created' | 'updated';
}[]>;
public abstract start(): Promise<void>; public abstract start(): Promise<void>;
public abstract stop(): Promise<void>; public abstract stop(): Promise<void>;

View File

@ -39,50 +39,39 @@ export class WebDavExposeProvider extends ExposeProvider {
this.webdavClient = new plugins.smartwebdav.WebdavClient(this.options.webdavCredentials); this.webdavClient = new plugins.smartwebdav.WebdavClient(this.options.webdavCredentials);
await this.ensureBaseDir(); await this.ensureBaseDir();
await this.houseKeeping(); await this.houseKeeping();
this.smartExposeRef.taskmanager.addAndScheduleTask( this.smartExposeRef.taskmanager.addAndScheduleTask(new plugins.taskbuffer.Task({
new plugins.taskbuffer.Task({
name: 'webdavHousekeeping', name: 'webdavHousekeeping',
taskFunction: async () => { taskFunction: async () => {
await this.houseKeeping(); await this.houseKeeping();
}, },
}), }), '0 * * * * *')
'0 * * * * *'
);
} }
public async stop(): Promise<void> { public async stop(): Promise<void> {
// Nothing to do here // Nothing to do here
} }
public async exposeFile( public async exposeFile(optionsArg: {
optionsArg: Parameters<ExposeProvider['exposeFile']>[0] smartFile: plugins.smartfile.SmartFile;
): Promise<{ url: string; id: string; status: 'created' | 'updated' }> { deleteAfterMillis?: number;
privateUrl?: boolean;
}): Promise<{ url: string; id: string; status: 'created' | 'updated' }> {
await this.ensureBaseDir(); await this.ensureBaseDir();
const fileId = plugins.smartunique.shortId(30); const fileId = plugins.smartunique.shortId(30);
console.log( console.log(`Expsing file under id: ${fileId}. (${
`Expsing file under id: ${fileId}. (${plugins.smartformat.prettyBytes( plugins.smartformat.prettyBytes(optionsArg.smartFile.contents.length)
optionsArg.smartFile.contents.length })`);
)})`
);
const webdavFilePath = await this.getFilePathById(fileId); const webdavFilePath = await this.getFilePathById(fileId);
const fileToUpload = await plugins.smartfile.SmartFile.fromBuffer( const fileToUpload = await plugins.smartfile.SmartFile.fromBuffer(webdavFilePath, optionsArg.smartFile.contents);
webdavFilePath,
optionsArg.smartFile.contents
);
await this.webdavClient.uploadSmartFileArray([fileToUpload]); await this.webdavClient.uploadSmartFileArray([fileToUpload]);
console.log(`checking file presence: ${webdavFilePath}`); console.log(`checking file presence: ${webdavFilePath}`);
const existsOnWebdav = await this.webdavClient.wdClient.exists(webdavFilePath); const existsOnWebdav = await this.webdavClient.wdClient.exists(webdavFilePath);
const publicUrl = plugins.smartpath.join( const publicUrl = plugins.smartpath.join(this.smartExposeRef.options.exposedBaseUrl, webdavFilePath);
this.smartExposeRef.options.exposedBaseUrl, console.log(`cehcking for file at ${publicUrl}`)
webdavFilePath
);
console.log(`cehcking for file at ${publicUrl}`);
const response = await plugins.smartrequest.getBinary(publicUrl); const response = await plugins.smartrequest.getBinary(publicUrl);
plugins.smartexpect.expect(response.body).toEqual(fileToUpload.contents); plugins.smartexpect.expect(response.body).toEqual(fileToUpload.contents);
if (optionsArg.deleteAfterMillis) { if (optionsArg.deleteAfterMillis) {
console.log( console.log(`Scheduling deletion of file with id: ${fileId} in ${optionsArg.deleteAfterMillis}ms...`);
`Scheduling deletion of file with id: ${fileId} in ${optionsArg.deleteAfterMillis}ms...`
);
plugins.smartdelay.delayFor(optionsArg.deleteAfterMillis).then(() => { plugins.smartdelay.delayFor(optionsArg.deleteAfterMillis).then(() => {
console.log(`Deleting file with id: ${fileId}...`); console.log(`Deleting file with id: ${fileId}...`);
this.deleteFileById(fileId); this.deleteFileById(fileId);
@ -96,20 +85,6 @@ export class WebDavExposeProvider extends ExposeProvider {
}; };
} }
public async exposeFileArray(optionsArg: Parameters<ExposeProvider['exposeFileArray']>[0]) {
const returnArray = [];
for (const smartFile of optionsArg.smartFiles) {
returnArray.push(
await this.exposeFile({
smartFile,
deleteAfterMillis: optionsArg.deleteAfterMillis,
privateUrl: optionsArg.privateUrl,
})
);
}
return returnArray;
}
public async wipeAll(): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }[]> { public async wipeAll(): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }[]> {
const directoryContents = await this.webdavClient.listDirectory(this.options.webdavSubPath); const directoryContents = await this.webdavClient.listDirectory(this.options.webdavSubPath);
await this.webdavClient.ensureEmptyDirectory(this.options.webdavSubPath); await this.webdavClient.ensureEmptyDirectory(this.options.webdavSubPath);

View File

@ -42,8 +42,4 @@ export class SmartExpose {
public async exposeFile(optionsArg: Parameters<ExposeProvider['exposeFile']>[0]) { public async exposeFile(optionsArg: Parameters<ExposeProvider['exposeFile']>[0]) {
return this.provider.exposeFile(optionsArg); return this.provider.exposeFile(optionsArg);
} }
public async exposeFileArray(optionsArg: Parameters<ExposeProvider['exposeFileArray']>[0]) {
return this.provider.exposeFileArray(optionsArg);
}
} }