fix(core): update

This commit is contained in:
2024-04-22 13:13:00 +02:00
commit 299b8267bb
18 changed files with 5338 additions and 0 deletions

8
ts/00_commitinfo_data.ts Normal file
View 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'
}

View 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';
}>
}

View 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
View 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
View File

@ -0,0 +1,2 @@
export * from './classes.exposeprovider.js';
export * from './classes.smartexpose.js';

12
ts/plugins.ts Normal file
View 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,
}