mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Enable generating device list
This commit is contained in:
parent
00f1f1397c
commit
1d5a4d059b
3 changed files with 57 additions and 3 deletions
|
|
@ -1,5 +1,10 @@
|
|||
// App Data that is derived from other app data
|
||||
|
||||
export function isDevice ( listing ) {
|
||||
if ( !listing.hasOwnProperty('endpoint') ) return false
|
||||
|
||||
return listing.endpoint.startsWith('/device/')
|
||||
}
|
||||
|
||||
export function isVideo ( app ) {
|
||||
return app.hasOwnProperty('thumbnail') && app.hasOwnProperty('timestamps')
|
||||
|
|
@ -13,6 +18,10 @@ export function getAppType ( app ) {
|
|||
return 'video'
|
||||
}
|
||||
|
||||
if ( isDevice( app ) ) {
|
||||
return 'device'
|
||||
}
|
||||
|
||||
if(app.category !== Object(app.category)) {
|
||||
console.warn('app has no categories', app)
|
||||
|
||||
|
|
|
|||
33
helpers/build-device-list.js
Normal file
33
helpers/build-device-list.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import axios from 'axios'
|
||||
|
||||
import { makeSlug } from './slug.js'
|
||||
|
||||
export function getDeviceEndpoint ( slug ) {
|
||||
return `/device/${ slug }`
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default async function () {
|
||||
|
||||
const devicesJsonUrl = `${process.env.VFUNCTIONS_URL}/api/devices`
|
||||
|
||||
const rawDeviceList = await axios.get(devicesJsonUrl)
|
||||
.then( response => {
|
||||
return response.data
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.warn('Error fetching device list', error)
|
||||
})
|
||||
|
||||
return rawDeviceList.map( device => {
|
||||
const slug = makeSlug( device.name )
|
||||
|
||||
return {
|
||||
...device,
|
||||
slug,
|
||||
endpoint: getDeviceEndpoint( slug ),
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue