mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-05 01:12:55 +01:00
fff80cd4e7
- fix(nexus): Preparing configs to be published - feat(nexus): Various fixes for opening left sources - fix(nexus): Fine-tune versions 1 internal commit(s) GitOrigin-RevId: 6c834cd3f4f5f18109a159a73503700dac63b0bb
40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
import documentsProto from '~/nexus/meta_api/proto/documents_service_grpc_web_pb'
|
|
import searchProto from '~/nexus/meta_api/proto/search_service_grpc_web_pb'
|
|
|
|
export default class MetaApi {
|
|
constructor (config) {
|
|
this.documentsClient = new documentsProto.DocumentsPromiseClient(config.url)
|
|
this.searchClient = new searchProto.SearchPromiseClient(config.url)
|
|
}
|
|
|
|
generateId (length) {
|
|
const result = []
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
const charactersLength = characters.length
|
|
for (let i = 0; i < length; i++) {
|
|
result.push(characters.charAt(Math.floor(Math.random() * charactersLength)))
|
|
}
|
|
return result.join('')
|
|
}
|
|
|
|
async getView (schema, documentId) {
|
|
const request = new documentsProto.TypedDocumentRequest()
|
|
request.setSchema(schema)
|
|
request.setDocumentId(documentId)
|
|
request.setSessionId(this.generateId(8))
|
|
const response = await this.documentsClient.get_view(request, { 'request-id': this.generateId(12) })
|
|
return response.toObject()
|
|
}
|
|
|
|
async search (schema, query, page, pageSize = 5) {
|
|
const request = new searchProto.SearchRequest()
|
|
request.setPage(page)
|
|
request.setPageSize(pageSize)
|
|
request.addSchemas(schema)
|
|
request.setQuery(query)
|
|
request.setSessionId(this.generateId(8))
|
|
const response = await this.searchClient.search(request, { 'request-id': this.generateId(12) })
|
|
return response.toObject()
|
|
}
|
|
}
|