fix(core): update
This commit is contained in:
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartexpose',
|
||||
version: '1.0.2',
|
||||
description: 'a package to expose things to the internet'
|
||||
}
|
43
ts/classes.exposeprovider.ts
Normal file
43
ts/classes.exposeprovider.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
/**
|
||||
* An expose provider provides a standardized interface for exposing data
|
||||
* Note: SmartExpose comes with some default implmentations of ExposeProvider
|
||||
*
|
||||
* notably:
|
||||
* - WebDavExposeProvider
|
||||
*/
|
||||
export abstract class ExposeProvider {
|
||||
|
||||
/**
|
||||
* Should take care of any housekeeping required to keep things in a healthy state.
|
||||
*/
|
||||
public abstract houseKeeping(): Promise<void>;
|
||||
|
||||
/**
|
||||
* should return a url with info about how to access the file
|
||||
* @param optionsArg
|
||||
*/
|
||||
public abstract exposeFile(optionsArg: {
|
||||
smartFile: plugins.smartfile.SmartFile,
|
||||
deleteAfterMillis?: number,
|
||||
privateUrl?: boolean, // wether the returned url should be private by design
|
||||
}): Promise<{
|
||||
url: string;
|
||||
id: string;
|
||||
status: 'created' | 'updated';
|
||||
}>;
|
||||
|
||||
public abstract start(): Promise<void>;
|
||||
|
||||
public abstract stop(): Promise<void>;
|
||||
|
||||
public abstract wipeAll(): Promise<{
|
||||
id: string;
|
||||
status: 'deleted' | 'failed' | 'notfound';
|
||||
}[]>
|
||||
public abstract wipeFileById(idArg: string): Promise<{
|
||||
id: string;
|
||||
status: 'deleted' | 'failed' | 'notfound';
|
||||
}>
|
||||
}
|
54
ts/classes.exposeprovider.webdav.ts
Normal file
54
ts/classes.exposeprovider.webdav.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { ExposeProvider } from './classes.exposeprovider.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export interface IWebdavExposeProviderOptions {
|
||||
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions,
|
||||
webdavSubPath: string,
|
||||
}
|
||||
|
||||
export class WebDavExposeProvider extends ExposeProvider {
|
||||
public webdavClient: plugins.smartwebdav.WebdavClient;
|
||||
public options: IWebdavExposeProviderOptions;
|
||||
|
||||
constructor(optionsArg: IWebdavExposeProviderOptions) {
|
||||
super();
|
||||
this.options = optionsArg;
|
||||
}
|
||||
|
||||
public async houseKeeping (): Promise<void> {
|
||||
const directoryContents = await this.webdavClient.listDirectory(this.options.webdavSubPath);
|
||||
for (const fileStat of directoryContents) {
|
||||
// lets read the meta.json file
|
||||
if (fileStat.filename.endsWith('.json')) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async ensureBaseDir (): Promise<void> {
|
||||
await this.webdavClient.ensureDirectory(this.options.webdavSubPath);
|
||||
}
|
||||
|
||||
public async start (): Promise<void> {
|
||||
this.webdavClient = new plugins.smartwebdav.WebdavClient(this.options.webdavCredentials);
|
||||
await this.ensureBaseDir();
|
||||
await this.houseKeeping();
|
||||
}
|
||||
|
||||
public async stop (): Promise<void> {
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
public async exposeFile (optionsArg: { smartFile: plugins.smartfile.SmartFile; deleteAfterMillis?: number; privateUrl?: boolean; }): Promise<{ url: string; id: string; status: 'created' | 'updated'; }> {
|
||||
await this.ensureBaseDir();
|
||||
|
||||
}
|
||||
|
||||
public async wipeAll (): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound'; }[]> {
|
||||
|
||||
}
|
||||
|
||||
public async wipeFileById (idArg: string): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound'; }> {
|
||||
|
||||
}
|
||||
}
|
33
ts/classes.smartexpose.ts
Normal file
33
ts/classes.smartexpose.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import type { ExposeProvider } from './classes.exposeprovider.js';
|
||||
import { WebDavExposeProvider } from './classes.exposeprovider.webdav.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export interface ISmartExposeOptions {
|
||||
deleteAfterMillis?: number,
|
||||
privateUrl?: boolean,
|
||||
}
|
||||
|
||||
export class SmartExpose {
|
||||
// STATIC
|
||||
public static createWithWebdav(optionsArg: {
|
||||
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions,
|
||||
webdavSubPath: string,
|
||||
exposedBaseUrl: string,
|
||||
exposeOptions: ISmartExposeOptions,
|
||||
}) {
|
||||
const provider = new WebDavExposeProvider({
|
||||
webdavCredentials: optionsArg.webdavCredentials,
|
||||
webdavSubPath: optionsArg.webdavSubPath,
|
||||
});
|
||||
const smartexposeInstance = new SmartExpose(provider, optionsArg.exposeOptions);
|
||||
return smartexposeInstance;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public taskmanager: plugins.taskbuffer.TaskManager;
|
||||
public options: ISmartExposeOptions;
|
||||
|
||||
constructor(provider: ExposeProvider, optionsArg: ISmartExposeOptions) {
|
||||
this.options = optionsArg;
|
||||
}
|
||||
}
|
2
ts/index.ts
Normal file
2
ts/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './classes.exposeprovider.js';
|
||||
export * from './classes.smartexpose.js';
|
12
ts/plugins.ts
Normal file
12
ts/plugins.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// @push.rocks scope
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartjson from '@push.rocks/smartjson';
|
||||
import * as smartwebdav from '@push.rocks/smartwebdav';
|
||||
import * as taskbuffer from '@push.rocks/taskbuffer';
|
||||
|
||||
export {
|
||||
smartfile,
|
||||
smartjson,
|
||||
smartwebdav,
|
||||
taskbuffer,
|
||||
}
|
Reference in New Issue
Block a user