-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
248 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { boot } from 'quasar/wrappers' | ||
import axios from 'axios' | ||
|
||
let API_ENDPOINT = process.env.ARCHIVARIUS_API_ENDPOINT | ||
if (localStorage.getItem('catalogChannel') !== null) { | ||
if (localStorage.getItem('catalogChannel') === 'production') { | ||
API_ENDPOINT = 'https://catalog.flipperzero.one/api/v0' | ||
} else { | ||
API_ENDPOINT = 'https://catalog.flipp.dev/api/v0' | ||
} | ||
} | ||
|
||
const api = axios.create({ | ||
baseURL: API_ENDPOINT, | ||
timeout: 25000, | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
|
||
export default boot(({ app }) => { | ||
// for use inside Vue files (Options API) through this.$axios and this.$api | ||
|
||
app.config.globalProperties.$axios = axios | ||
// ^ ^ ^ this will allow you to use this.$axios (for Vue Options API form) | ||
// so you won't necessarily have to import axios in each vue file | ||
|
||
app.config.globalProperties.$api = api | ||
// ^ ^ ^ this will allow you to use this.$api (for Vue Options API form) | ||
// so you can easily perform requests against your app's API | ||
}) | ||
|
||
export { axios, api } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import semver from 'semver' | ||
import { axios, api } from 'boot/axios' | ||
import { camelCaseDeep, unpack } from 'util/util' | ||
|
||
async function fetchChannels (target) { | ||
return await axios | ||
.get('https://update.flipperzero.one/firmware/directory.json') | ||
.then(({ data }) => { | ||
const release = data.channels.find((e) => e.id === 'release') | ||
const rc = data.channels.find((e) => e.id === 'release-candidate') | ||
const dev = data.channels.find((e) => e.id === 'development') | ||
const params = new URLSearchParams(location.search) | ||
const customSource = { | ||
url: params.get('url'), | ||
channel: params.get('channel'), | ||
version: params.get('version'), | ||
target: params.get('target') | ||
} | ||
|
||
function formatChannel (channel) { | ||
channel.versions.sort((a, b) => { | ||
if (semver.lt(a.version, b.version)) return 1 | ||
else return -1 | ||
}) | ||
const output = { | ||
version: '', | ||
date: '', | ||
url: '', | ||
files: [], | ||
changelog: '' | ||
} | ||
const updater = channel.versions[0].files.find( | ||
(file) => file.target === 'f' + target && file.type === 'update_tgz' | ||
) | ||
if (updater) { | ||
output.url = updater.url | ||
} | ||
output.version = channel.versions[0].version | ||
output.date = new Date(channel.versions[0].timestamp * 1000) | ||
.toISOString() | ||
.slice(0, 10) | ||
output.files = channel.versions[0].files.sort((a, b) => { | ||
if (a.url.match(/[\w.]+$/g)[0] > b.url.match(/[\w.]+$/g)[0]) return 1 | ||
else return -1 | ||
}) | ||
output.changelog = channel.versions[0].changelog | ||
return output | ||
} | ||
|
||
const releaseChannel = formatChannel(release) | ||
const rcChannel = formatChannel(rc) | ||
const devChannel = formatChannel(dev) | ||
|
||
let customChannel | ||
if (customSource.url) { | ||
customChannel = { | ||
channel: customSource.channel, | ||
version: customSource.version, | ||
date: new Date().toISOString().slice(0, 10), | ||
url: customSource.url, | ||
files: [ | ||
{ | ||
url: customSource.url, | ||
type: 'update_tgz', | ||
target: customSource.target | ||
} | ||
] | ||
} | ||
} | ||
return { | ||
release: releaseChannel, | ||
rc: rcChannel, | ||
dev: devChannel, | ||
custom: customChannel | ||
} | ||
}) | ||
.catch(({ status }) => { | ||
if (status >= 400) { | ||
throw new Error('Failed to fetch firmware channels (' + status + ')') | ||
} | ||
}) | ||
} | ||
|
||
async function fetchFirmware (url) { | ||
return await axios | ||
.get(url, { responseType: 'arraybuffer' }) | ||
.then(async ({ data }) => { | ||
return unpack(data) | ||
}) | ||
.catch(({ status }) => { | ||
if (status >= 400) { | ||
throw new Error('Failed to fetch resources (' + status + ')') | ||
} | ||
}) | ||
} | ||
|
||
async function fetchRegions () { | ||
return axios | ||
.get('https://update.flipperzero.one/regions/api/v0/bundle') | ||
.then(({ data }) => { | ||
if (data.error) { | ||
throw new Error(data.error.text) | ||
} else if (data.success) { | ||
return data.success | ||
} | ||
}) | ||
.catch(({ status }) => { | ||
if (status >= 400) { | ||
throw new Error('Failed to fetch region (' + status + ')') | ||
} | ||
}) | ||
} | ||
|
||
async function fetchCategories (params) { | ||
return await api.get('/category', { params }).then(({ data }) => { | ||
return data.map((category) => camelCaseDeep(category)) | ||
}) | ||
} | ||
|
||
async function fetchAppsShort (params) { | ||
return await api.get('/application', { params }).then(({ data }) => { | ||
return data.map((app) => camelCaseDeep(app)) | ||
}) | ||
} | ||
|
||
async function fetchAppById (id, params) { | ||
if (!params.target) { | ||
delete params.target | ||
} | ||
if (!params.api) { | ||
delete params.api | ||
} | ||
return await api.get(`/application/${id}`, { params }).then(({ data }) => { | ||
return camelCaseDeep(data) | ||
}) | ||
} | ||
|
||
async function fetchAppFap (params) { | ||
return await api | ||
.get(`/application/version/${params.versionId}/build/compatible`, { | ||
params: { | ||
target: params.target, | ||
api: params.api | ||
}, | ||
responseType: 'arraybuffer' | ||
}) | ||
.then(({ data }) => { | ||
return data | ||
}) | ||
.catch(({ status }) => { | ||
if (status >= 400) { | ||
throw new Error('Failed to fetch application build (' + status + ')') | ||
} | ||
}) | ||
} | ||
|
||
async function fetchAppsVersions (uids) { | ||
const size = 100 | ||
const subUids = [] | ||
|
||
for (let i = 0; i < Math.ceil(uids.length / size); i++) { | ||
subUids[i] = uids.slice(i * size, i * size + size) | ||
} | ||
|
||
const allVersions = [] | ||
for (const sliceUids of subUids) { | ||
await api | ||
.post('/1/application/versions', { | ||
application_versions: sliceUids, | ||
limit: size | ||
}) | ||
.then(({ data }) => allVersions.push(...data)) | ||
} | ||
|
||
const versions = allVersions.map((version) => camelCaseDeep(version)) | ||
return versions | ||
} | ||
|
||
async function submitAppReport (id, report) { | ||
return api.post(`/application/${id}/issue`, { | ||
...report | ||
}) | ||
} | ||
|
||
export { | ||
fetchChannels, | ||
fetchFirmware, | ||
fetchRegions, | ||
fetchCategories, | ||
fetchAppsShort, | ||
fetchAppById, | ||
fetchAppFap, | ||
fetchAppsVersions, | ||
submitAppReport | ||
} |
Oops, something went wrong.