mirror of
https://github.com/balzack/databag.git
synced 2025-04-23 18:15:19 +00:00
renaming media interface
This commit is contained in:
parent
29e868bd22
commit
e606d9af69
@ -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<string> }> {
|
||||
return { size: 0, getData: async (position: number, length: number)=>('') };
|
||||
}
|
||||
|
@ -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<string, Map<string, { item: ChannelItem; channel: Channel }>>;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
export interface Files {
|
||||
read(source: any): Promise<{ size: number, getData: (position: number, length: number)=>Promise<string> }>;
|
||||
write(): Promise<{ setData: (data: string)=>Promise<void>, getPath: ()=>Promise<string> }>;
|
||||
}
|
@ -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<string, { item: TopicItem; topic: Topic }>;
|
||||
|
||||
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<string> {
|
||||
public async addTopic(sealed: boolean, type: string, subject: (asset: {assetId: string, context: any}[]) => any, files: AssetSource[], progress: (percent: number)=>boolean): Promise<string> {
|
||||
// { assets, text, textColor, textSize }
|
||||
// asset: { image: { thumb: string, full: string }}
|
||||
// asset encrypted: { encrypted: { type: string, thumb: string, parts: { blockIv: string, partId: string } } }
|
||||
|
@ -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<Session | null> {
|
||||
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<number> {
|
||||
@ -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<Session> {
|
||||
@ -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<Session> {
|
||||
@ -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<void> {
|
||||
|
@ -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);
|
||||
|
@ -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<string, { item: ChannelItem; channel: Channel }>;
|
||||
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user