From e606d9af691de9a0adfeef9f1399b7c2de8ea85d Mon Sep 17 00:00:00 2001 From: balzack Date: Thu, 28 Nov 2024 10:01:58 -0800 Subject: [PATCH] renaming media interface --- app/client/web/src/MediaFiles.ts | 4 ++-- app/sdk/src/contact.ts | 12 ++++++------ app/sdk/src/files.ts | 4 ---- app/sdk/src/focus.ts | 11 +++++------ app/sdk/src/index.ts | 20 ++++++++++---------- app/sdk/src/session.ts | 12 ++++++------ app/sdk/src/stream.ts | 12 ++++++------ 7 files changed, 35 insertions(+), 40 deletions(-) delete mode 100644 app/sdk/src/files.ts diff --git a/app/client/web/src/MediaFiles.ts b/app/client/web/src/MediaFiles.ts index 247966c5..bd0dc8e6 100644 --- a/app/client/web/src/MediaFiles.ts +++ b/app/client/web/src/MediaFiles.ts @@ -1,6 +1,6 @@ -import { Files } from 'databag-client-sdk' +import { Media } from 'databag-client-sdk' -export class MediaFiles implements Files { +export class MediaFiles implements Media { public async read(source: any): Promise<{ size: number, getData: (position: number, length: number)=>Promise }> { return { size: 0, getData: async (position: number, length: number)=>('') }; } diff --git a/app/sdk/src/contact.ts b/app/sdk/src/contact.ts index 407f379b..a14c81d4 100644 --- a/app/sdk/src/contact.ts +++ b/app/sdk/src/contact.ts @@ -8,7 +8,7 @@ import type { ArticleDetail, ChannelSummary, ChannelDetail, CardProfile, CardDet import { defaultCardItem, defaultChannelItem } from './items'; import { Store } from './store'; import { Crypto } from './crypto'; -import { Files } from './files'; +import { Media } from './media'; import { getCards } from './net/getCards'; import { getCardProfile } from './net/getCardProfile'; import { getCardDetail } from './net/getCardDetail'; @@ -52,7 +52,7 @@ export class ContactModule implements Contact { private focus: FocusModule | null; private crypto: Crypto | null; - private files: Files | null; + private media: Media | null; private store: Store; private revision: number; private nextRevision: number | null; @@ -74,7 +74,7 @@ export class ContactModule implements Contact { // view of channels private channelEntries: Map>; - constructor(log: Logging, store: Store, crypto: Crypto | null, files: Files | null, guid: string, token: string, node: string, secure: boolean, articleTypes: string[], channelTypes: string[]) { + constructor(log: Logging, store: Store, crypto: Crypto | null, media: Media | null, guid: string, token: string, node: string, secure: boolean, articleTypes: string[], channelTypes: string[]) { this.guid = guid; this.token = token; this.node = node; @@ -82,7 +82,7 @@ export class ContactModule implements Contact { this.log = log; this.store = store; this.crypto = crypto; - this.files = files; + this.media = media; this.emitter = new EventEmitter(); this.articleTypes = articleTypes; this.channelTypes = channelTypes; @@ -621,9 +621,9 @@ export class ContactModule implements Contact { const channelKey = channelEntry.item.channelKey; const sealEnabled = Boolean(this.seal); const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(node); - this.focus = new FocusModule(this.log, this.store, this.crypto, this.files, cardId, channelId, this.guid, { node, secure: !insecure, token: `${guid}.${token}` }, channelKey, sealEnabled, revision); + this.focus = new FocusModule(this.log, this.store, this.crypto, this.media, cardId, channelId, this.guid, { node, secure: !insecure, token: `${guid}.${token}` }, channelKey, sealEnabled, revision); } else { - this.focus = new FocusModule(this.log, this.store, this.crypto, this.files, cardId, channelId, this.guid, null, null, false, 0); + this.focus = new FocusModule(this.log, this.store, this.crypto, this.media, cardId, channelId, this.guid, null, null, false, 0); } return this.focus; } diff --git a/app/sdk/src/files.ts b/app/sdk/src/files.ts deleted file mode 100644 index ec081e06..00000000 --- a/app/sdk/src/files.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface Files { - read(source: any): Promise<{ size: number, getData: (position: number, length: number)=>Promise }>; - write(): Promise<{ setData: (data: string)=>Promise, getPath: ()=>Promise }>; -} diff --git a/app/sdk/src/focus.ts b/app/sdk/src/focus.ts index 16b293ea..f7f29b78 100644 --- a/app/sdk/src/focus.ts +++ b/app/sdk/src/focus.ts @@ -5,8 +5,7 @@ import type { Topic, Asset, AssetSource, Participant } from './types'; import type { Logging } from './logging'; import { Store } from './store'; import { Crypto } from './crypto'; -import { Files } from './files'; -import { Files } from './files'; +import { Media } from './media'; import { HostingMode } from './types'; import { defaultTopicItem } from './items'; import { getChannelTopics } from './net/getChannelTopics'; @@ -29,7 +28,7 @@ export class FocusModule implements Focus { private log: Logging; private emitter: EventEmitter; private crypto: Crypto | null; - private files: Files | null; + private media: Media | null; private store: Store; private guid: string; private connection: { node: string; secure: boolean; token: string } | null; @@ -49,14 +48,14 @@ export class FocusModule implements Focus { // view of topics private topicEntries: Map; - constructor(log: Logging, store: Store, crypto: Crypto | null, files: Files | null, cardId: string | null, channelId: string, guid: string, connection: { node: string; secure: boolean; token: string } | null, channelKey: string, sealEnabled: boolean, revision: number) { + constructor(log: Logging, store: Store, crypto: Crypto | null, media: Media | null, cardId: string | null, channelId: string, guid: string, connection: { node: string; secure: boolean; token: string } | null, channelKey: string, sealEnabled: boolean, revision: number) { this.cardId = cardId; this.channelId = channelId; this.log = log; this.emitter = new EventEmitter(); this.store = store; this.crypto = crypto; - this.files = files; + this.media = media; this.guid = guid; this.connection = connection; this.channelKey = channelKey; @@ -282,7 +281,7 @@ export class FocusModule implements Focus { }); } - public async addTopic(sealed: boolean, type: string, subject: (asset: {assetId: string, context: any}[]) => any, assets: AssetSource[], progress: (percent: number)=>boolean): Promise { + public async addTopic(sealed: boolean, type: string, subject: (asset: {assetId: string, context: any}[]) => any, files: AssetSource[], progress: (percent: number)=>boolean): Promise { // { assets, text, textColor, textSize } // asset: { image: { thumb: string, full: string }} // asset encrypted: { encrypted: { type: string, thumb: string, parts: { blockIv: string, partId: string } } } diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index dd9f71b4..5bbe513f 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -15,27 +15,27 @@ import type { Session, Node, Contributor } from './api'; import type { Params, SessionParams } from './types'; import type { Login } from './entities'; import type { Crypto } from './crypto'; -import type { Files } from './files'; +import type { Media } from './media'; import type { WebStore, SqlStore } from './store'; export * from './api'; export * from './types'; export { WebStore, SqlStore } from './store'; export { Crypto } from './crypto'; -export { Files } from './files'; +export { Media } from './media'; export class DatabagSDK { private log: Logging; private crypto: Crypto | null; - private files: Files | null; + private media: Media | null; private store: Store; private params: Params; - constructor(params: Params, crypto?: Crypto, files?: Files, log?: Logging) { + constructor(params: Params, crypto?: Crypto, media?: Media, log?: Logging) { this.store = new NoStore(); this.params = params; this.crypto = crypto ? crypto : null; - this.files = files ? files : null; + this.media = media ? media : null; this.log = log ? log : new ConsoleLogging(); this.log.info('databag sdk'); } @@ -44,14 +44,14 @@ export class DatabagSDK { const { articleTypes, channelTypes } = this.params; this.store = new OfflineStore(this.log, sql); const login = await this.store.init(); - return login ? new SessionModule(this.store, this.crypto, this.log, this.files, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null; + return login ? new SessionModule(this.store, this.crypto, this.log, this.media, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null; } public async initOnlineStore(web: WebStore): Promise { const { articleTypes, channelTypes } = this.params; this.store = new OnlineStore(this.log, web); const login = await this.store.init(); - return login ? new SessionModule(this.store, this.crypto, this.log, this.files, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null; + return login ? new SessionModule(this.store, this.crypto, this.log, this.media, login.guid, login.token, login.node, login.secure, login.timestamp, articleTypes, channelTypes) : null; } public async available(node: string, secure: boolean): Promise { @@ -75,7 +75,7 @@ export class DatabagSDK { pushSupported, }; await this.store.setLogin(login); - return new SessionModule(this.store, this.crypto, this.log, this.files, guid, appToken, node, secure, created, articleTypes, channelTypes); + return new SessionModule(this.store, this.crypto, this.log, this.media, guid, appToken, node, secure, created, articleTypes, channelTypes); } public async access(node: string, secure: boolean, token: string, params: SessionParams): Promise { @@ -91,7 +91,7 @@ export class DatabagSDK { pushSupported, }; await this.store.setLogin(login); - return new SessionModule(this.store, this.crypto, this.log, this.files, guid, appToken, node, secure, created, articleTypes, channelTypes); + return new SessionModule(this.store, this.crypto, this.log, this.media, guid, appToken, node, secure, created, articleTypes, channelTypes); } public async create(handle: string, password: string, node: string, secure: boolean, token: string | null, params: SessionParams): Promise { @@ -108,7 +108,7 @@ export class DatabagSDK { pushSupported, }; await this.store.setLogin(login); - return new SessionModule(this.store, this.crypto, this.log, this.files, guid, appToken, node, secure, created, articleTypes, channelTypes); + return new SessionModule(this.store, this.crypto, this.log, this.media, guid, appToken, node, secure, created, articleTypes, channelTypes); } public async remove(session: Session): Promise { diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index cee8c2a7..7924917f 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -18,13 +18,13 @@ import { Call } from './types'; import { Store } from './store'; import type { Logging } from './logging'; import type { Crypto } from './crypto'; -import type { Files } from './files'; +import type { Media } from './media'; export class SessionModule implements Session { private emitter: EventEmitter; private store: Store; private crypto: Crypto | null; - private files: Files | null; + private media: Media | null; private log: Logging; private guid: string; private token: string; @@ -44,12 +44,12 @@ export class SessionModule implements Session { private channelTypes: string[]; private articleTypes: string[]; - constructor(store: Store, crypto: Crypto | null, log: Logging, files: Files | null, guid: string, token: string, node: string, secure: boolean, loginTimestamp: number, articleTypes: string[], channelTypes: string[]) { + constructor(store: Store, crypto: Crypto | null, log: Logging, media: Media | null, guid: string, token: string, node: string, secure: boolean, loginTimestamp: number, articleTypes: string[], channelTypes: string[]) { log.info('new databag session'); this.store = store; this.crypto = crypto; - this.files = files; + this.media = media; this.log = log; this.guid = guid; this.token = token; @@ -63,10 +63,10 @@ export class SessionModule implements Session { this.identity = new IdentityModule(log, this.store, guid, token, node, secure); this.settings = new SettingsModule(log, this.store, this.crypto, guid, token, node, secure); - this.contact = new ContactModule(log, this.store, this.crypto, this.files, guid, token, node, secure, articleTypes, channelTypes); + this.contact = new ContactModule(log, this.store, this.crypto, this.media, guid, token, node, secure, articleTypes, channelTypes); this.alias = new AliasModule(log, this.settings, this.store, guid, token, node, secure); this.attribute = new AttributeModule(log, this.settings, this.store, guid, token, node, secure); - this.stream = new StreamModule(log, this.store, this.crypto, this.files, guid, token, node, secure, channelTypes); + this.stream = new StreamModule(log, this.store, this.crypto, this.media, guid, token, node, secure, channelTypes); this.content = new ContentModule(log, this.crypto, this.contact, this.stream); this.ring = new RingModule(log); this.connection = new Connection(log, token, node, secure); diff --git a/app/sdk/src/stream.ts b/app/sdk/src/stream.ts index a9723b55..2eb12648 100644 --- a/app/sdk/src/stream.ts +++ b/app/sdk/src/stream.ts @@ -6,7 +6,7 @@ import type { ChannelItem } from './items'; import type { Channel, Topic, Asset, Tag, Participant } from './types'; import { Store } from './store'; import { Crypto } from './crypto'; -import { Files } from './files'; +import { Media } from './media'; import { addChannel } from './net/addChannel'; import { removeChannel } from './net/removeChannel'; import { getChannels } from './net/getChannels'; @@ -27,7 +27,7 @@ export class StreamModule { private log: Logging; private store: Store; private crypto: Crypto | null; - private files: Files | null; + private media: Media | null; private guid: string; private token: string; private node: string; @@ -46,7 +46,7 @@ export class StreamModule { // view of channels private channelEntries: Map; - constructor(log: Logging, store: Store, crypto: Crypto | null, files: Files | null, guid: string, token: string, node: string, secure: boolean, channelTypes: string[]) { + constructor(log: Logging, store: Store, crypto: Crypto | null, media: Media | null, guid: string, token: string, node: string, secure: boolean, channelTypes: string[]) { this.guid = guid; this.token = token; this.node = node; @@ -54,7 +54,7 @@ export class StreamModule { this.log = log; this.store = store; this.crypto = crypto; - this.files = files; + this.media = media; this.focus = null; this.seal = null; this.unsealAll = false; @@ -379,10 +379,10 @@ export class StreamModule { const channelKey = entry.item.channelKey; const sealEnabled = Boolean(this.seal); const revision = entry.item.summary.revision; - this.focus = new FocusModule(this.log, this.store, this.crypto, this.files, null, channelId, this.guid, { node, secure, token }, channelKey, sealEnabled, revision); + this.focus = new FocusModule(this.log, this.store, this.crypto, this.media, null, channelId, this.guid, { node, secure, token }, channelKey, sealEnabled, revision); } else { - this.focus = new FocusModule(this.log, this.store, this.crypto, this.files, cardId, channelId, this.guid, null, null, false, 0); + this.focus = new FocusModule(this.log, this.store, this.crypto, this.media, cardId, channelId, this.guid, null, null, false, 0); } return this.focus;