mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
cleaning up
This commit is contained in:
@@ -1,24 +1,12 @@
|
||||
import { HttpService } from '../http.service'
|
||||
import { MockApiService } from './embassy/embassy-mock-api.service'
|
||||
import { LiveApiService } from './embassy/embassy-live-api.service'
|
||||
import { MockApiService } from './embassy-mock-api.service'
|
||||
import { LiveApiService } from './embassy-live-api.service'
|
||||
import { ConfigService } from '../config.service'
|
||||
import { PatchDbService } from '../patch-db/patch-db.service'
|
||||
import { MarketplaceLiveApiService } from './marketplace/marketplace-live-api.service'
|
||||
import { MarketplaceMockApiService } from './marketplace/marketplace-mock-api.service'
|
||||
import { ApiService } from './embassy/embassy-api.service'
|
||||
|
||||
export function ApiServiceFactory (config: ConfigService, http: HttpService) {
|
||||
if (config.mocks.enabled) {
|
||||
return new MockApiService(http, config)
|
||||
return new MockApiService(http)
|
||||
} else {
|
||||
return new LiveApiService(http, config)
|
||||
return new LiveApiService(http)
|
||||
}
|
||||
}
|
||||
|
||||
export function MarketplaceApiServiceFactory (config: ConfigService, patch: PatchDbService, apiService: ApiService) {
|
||||
if (config.mocks.enabled) {
|
||||
return new MarketplaceMockApiService(config, patch)
|
||||
} else {
|
||||
return new MarketplaceLiveApiService(apiService, config, patch)
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ export module RR {
|
||||
sessions: { [hash: string]: Session }
|
||||
}
|
||||
|
||||
export type KillSessionsReq = WithExpire<{ hashes: string[] }> // sessions.kill
|
||||
export type KillSessionsReq = WithExpire<{ ids: string[] }> // sessions.kill
|
||||
export type KillSessionsRes = WithRevision<null>
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Subject, Observable } from 'rxjs'
|
||||
import { Http, Update, Operation, Revision, Source, Store } from 'patch-db-client'
|
||||
import { RR } from '../api.types'
|
||||
import { RR } from './api.types'
|
||||
import { DataModel } from 'src/app/services/patch-db/data-model'
|
||||
import { Method, RequestError } from '../../http.service'
|
||||
import { RequestError } from '../http.service'
|
||||
|
||||
export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
|
||||
protected readonly sync = new Subject<Update<DataModel>>()
|
||||
@@ -65,7 +65,15 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
abstract marketplaceProxy (url: string, params: { [key: string]: any }): Promise<any>
|
||||
abstract getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes>
|
||||
|
||||
abstract getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes>
|
||||
|
||||
abstract getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes>
|
||||
|
||||
abstract getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes>
|
||||
|
||||
abstract getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes>
|
||||
|
||||
// protected abstract setPackageMarketplaceRaw (params: RR.SetPackageMarketplaceReq): Promise<RR.SetPackageMarketplaceRes>
|
||||
// setPackageMarketplace = (params: RR.SetPackageMarketplaceReq) => this.syncResponse(
|
||||
@@ -1,16 +1,14 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { HttpService, Method } from '../../http.service'
|
||||
import { HttpService, Method } from '../http.service'
|
||||
import { ApiService } from './embassy-api.service'
|
||||
import { RR } from '../api.types'
|
||||
import { RR } from './api.types'
|
||||
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
|
||||
import { ConfigService } from '../../config.service'
|
||||
|
||||
@Injectable()
|
||||
export class LiveApiService extends ApiService {
|
||||
|
||||
constructor (
|
||||
private readonly http: HttpService,
|
||||
private readonly config: ConfigService,
|
||||
) { super() }
|
||||
|
||||
async getStatic (url: string): Promise<string> {
|
||||
@@ -87,10 +85,45 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
async marketplaceProxy (url: string, params: { [key: string]: any }) {
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
return this.http.httpRequest({
|
||||
method: Method.GET,
|
||||
url,
|
||||
url: '/marketplace/eos/latest',
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise <RR.GetMarketplaceDataRes> {
|
||||
return this.http.httpRequest({
|
||||
method: Method.GET,
|
||||
url: '/marketplace/package/data',
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise <RR.GetMarketplacePackagesRes> {
|
||||
return this.http.httpRequest({
|
||||
method: Method.GET,
|
||||
url: '/marketplace/package/index',
|
||||
params: {
|
||||
...params,
|
||||
ids: JSON.stringify(params.ids),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise <RR.GetReleaseNotesRes> {
|
||||
return this.http.httpRequest({
|
||||
method: Method.GET,
|
||||
url: '/marketplace/package/release-notes',
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
async getLatestVersion (params: RR.GetLatestVersionReq): Promise <RR.GetLatestVersionRes> {
|
||||
return this.http.httpRequest({
|
||||
method: Method.GET,
|
||||
url: '/marketplace/latest-version',
|
||||
params,
|
||||
})
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { pauseFor } from '../../../util/misc.util'
|
||||
import { pauseFor } from '../../util/misc.util'
|
||||
import { ApiService } from './embassy-api.service'
|
||||
import { Operation, PatchOp } from 'patch-db-client'
|
||||
import { InstallProgress, PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
|
||||
import { RR, WithRevision } from '../api.types'
|
||||
import { RR, WithRevision } from './api.types'
|
||||
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
|
||||
import { Mock } from '../api.fixures'
|
||||
import { HttpService } from '../../http.service'
|
||||
import markdown from '!!raw-loader!src/assets/markdown/md-sample.md'
|
||||
import { ConfigService } from '../../config.service'
|
||||
import { Mock } from './api.fixures'
|
||||
import { HttpService } from '../http.service'
|
||||
import markdown from 'raw-loader!src/assets/markdown/md-sample.md'
|
||||
|
||||
@Injectable()
|
||||
export class MockApiService extends ApiService {
|
||||
@@ -16,7 +15,6 @@ export class MockApiService extends ApiService {
|
||||
|
||||
constructor (
|
||||
private readonly http: HttpService,
|
||||
private readonly config: ConfigService,
|
||||
) { super() }
|
||||
|
||||
async getStatic (url: string): Promise<string> {
|
||||
@@ -110,7 +108,7 @@ export class MockApiService extends ApiService {
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/version',
|
||||
value: this.config.version + '.1',
|
||||
value: '3.1.0',
|
||||
},
|
||||
]
|
||||
await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
|
||||
@@ -119,7 +117,7 @@ export class MockApiService extends ApiService {
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/version',
|
||||
value: this.config.version,
|
||||
value: require('../../../../package.json').version,
|
||||
},
|
||||
]
|
||||
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch: patch2 } })
|
||||
@@ -147,8 +145,34 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
async marketplaceProxy (params) {
|
||||
return null
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.MarketplaceEos
|
||||
}
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
categories: ['featured', 'bitcoin', 'lightning', 'data', 'messaging', 'social', 'alt coin'],
|
||||
}
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.MarketplacePkgsList
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.ReleaseNotes
|
||||
}
|
||||
|
||||
async getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes> {
|
||||
await pauseFor(2000)
|
||||
return params.ids.reduce((obj, id) => {
|
||||
obj[id] = '1.3.0'
|
||||
return obj
|
||||
}, { })
|
||||
}
|
||||
|
||||
// async setPackageMarketplaceRaw (params: RR.SetPackageMarketplaceReq): Promise<RR.SetPackageMarketplaceRes> {
|
||||
@@ -1,35 +0,0 @@
|
||||
import { RR } from '../api.types'
|
||||
import { ConfigService } from '../../config.service'
|
||||
import { PatchDbService } from '../../patch-db/patch-db.service'
|
||||
import { ServerInfo } from '../../patch-db/data-model'
|
||||
import { AuthState } from '../../auth.service'
|
||||
import { takeWhile } from 'rxjs/operators'
|
||||
|
||||
export abstract class MarketplaceApiService {
|
||||
private server: ServerInfo
|
||||
|
||||
constructor (
|
||||
readonly config: ConfigService,
|
||||
readonly patch: PatchDbService,
|
||||
) { }
|
||||
|
||||
init (auth: AuthState) {
|
||||
this.patch.watch$('server-info')
|
||||
.pipe(
|
||||
takeWhile(() => auth === AuthState.VERIFIED),
|
||||
)
|
||||
.subscribe(server => {
|
||||
this.server = server
|
||||
})
|
||||
}
|
||||
|
||||
abstract getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes>
|
||||
|
||||
abstract getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes>
|
||||
|
||||
abstract getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes>
|
||||
|
||||
abstract getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes>
|
||||
|
||||
abstract getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes>
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Method } from '../../http.service'
|
||||
import { RR } from '../api.types'
|
||||
import { MarketplaceApiService } from './marketplace-api.service'
|
||||
import { PatchDbService } from '../../patch-db/patch-db.service'
|
||||
import { ConfigService } from '../../config.service'
|
||||
import { ApiService } from '../embassy/embassy-api.service'
|
||||
|
||||
@Injectable()
|
||||
export class MarketplaceLiveApiService extends MarketplaceApiService {
|
||||
|
||||
constructor (
|
||||
private readonly embassyApiService: ApiService,
|
||||
config: ConfigService,
|
||||
patch: PatchDbService,
|
||||
) {
|
||||
super( config, patch)
|
||||
}
|
||||
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
return this.embassyApiService.marketplaceProxy('/marketplace/eos', params)
|
||||
}
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise < RR.GetMarketplaceDataRes > {
|
||||
return this.embassyApiService.marketplaceProxy('/marketplace/package/data', params)
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise < RR.GetMarketplacePackagesRes > {
|
||||
return this.embassyApiService.marketplaceProxy('/marketplace/package/packages', { ...params, ids: JSON.stringify(params.ids) })
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise < RR.GetReleaseNotesRes > {
|
||||
return this.embassyApiService.marketplaceProxy('/marketplace/package/release-notes', params)
|
||||
}
|
||||
|
||||
async getLatestVersion (params: RR.GetLatestVersionReq): Promise < RR.GetLatestVersionRes > {
|
||||
return this.embassyApiService.marketplaceProxy('/marketplace/package/latest-version', params)
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { pauseFor } from '../../../util/misc.util'
|
||||
import { RR } from '../api.types'
|
||||
import { Mock } from '../api.fixures'
|
||||
import { MarketplaceApiService } from './marketplace-api.service'
|
||||
import { PatchDbService } from '../../patch-db/patch-db.service'
|
||||
import { ConfigService } from '../../config.service'
|
||||
|
||||
@Injectable()
|
||||
export class MarketplaceMockApiService extends MarketplaceApiService {
|
||||
constructor (
|
||||
config: ConfigService,
|
||||
patch: PatchDbService,
|
||||
) {
|
||||
super(config, patch)
|
||||
}
|
||||
|
||||
// marketplace
|
||||
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.MarketplaceEos
|
||||
}
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
categories: ['featured', 'bitcoin', 'lightning', 'data', 'messaging', 'social', 'alt coin'],
|
||||
}
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.MarketplacePkgsList
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.ReleaseNotes
|
||||
}
|
||||
|
||||
async getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes> {
|
||||
await pauseFor(2000)
|
||||
return params.ids.reduce((obj, id) => {
|
||||
obj[id] = this.patch.getData()['package-data']?.[id]?.manifest.version.replace('0', '1')
|
||||
return obj
|
||||
}, { })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user