Skip to content

Commit

Permalink
fix(lang): metadataLocation local files lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
slvnperron committed Jul 14, 2019
1 parent be395f5 commit 7cf9a05
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/bp/lang-server/service/download-manager.ts
@@ -1,6 +1,8 @@
import Axios from 'axios'
import fse from 'fs-extra'
import ms from 'ms'
import path from 'path'
import { URL } from 'url'

import ModelDownload from './model-download'

Expand Down Expand Up @@ -57,11 +59,31 @@ export default class DownloadManager {
}

async refreshMeta() {
try {
new URL(this.metaUrl)
return this.refreshRemoteMeta()
} catch (e) {
debug('Fetching models locally', { url: this.metaUrl })
return this.refreshLocalMeta()
}
}

async refreshRemoteMeta() {
try {
const { data } = (await Axios.get(this.metaUrl)) as { data: Meta }
this.meta = data
} catch (err) {
debug('Error fecthing models', { url: this.metaUrl, message: err.message })
debug('Error fetching models', { url: this.metaUrl, message: err.message })
}
}

async refreshLocalMeta() {
const filePath = path.isAbsolute(this.metaUrl) ? this.metaUrl : path.resolve(process.APP_DATA_PATH, this.metaUrl)
try {
const json = fse.readJSONSync(filePath)
this.meta = json
} catch (err) {
debug('Error reading metadata file', { file: filePath, message: err.message })
}
}

Expand Down

0 comments on commit 7cf9a05

Please sign in to comment.