mirror of
https://github.com/ivabus/www
synced 2024-11-10 13:55:14 +03:00
fix types and default placeholder values
This commit is contained in:
parent
201fc97544
commit
c547eafe19
|
@ -6,56 +6,57 @@ import type { AirtablePackage } from './types';
|
|||
const airtablePackagesBase = base(process.env.AIRTABLE_PACKAGES_BASE);
|
||||
|
||||
|
||||
export const getAllAirtablePackages = async () : Promise<AirtablePackage[]> => {
|
||||
const allRecords = await airtablePackagesBase('packages')
|
||||
.select({
|
||||
maxRecords: 100,
|
||||
view: '_api'
|
||||
}).all();
|
||||
export const getAllAirtablePackages = async (): Promise<AirtablePackage[]> => {
|
||||
const allRecords = await airtablePackagesBase('packages')
|
||||
.select({
|
||||
maxRecords: 100,
|
||||
view: '_api'
|
||||
}).all();
|
||||
|
||||
const packages: AirtablePackage[] = allRecords.map((record) => {
|
||||
return {
|
||||
airtable_record_id: record.id,
|
||||
..._.pick(record.fields, [
|
||||
'slug',
|
||||
'homepage',
|
||||
'maintainer',
|
||||
'name',
|
||||
'version',
|
||||
'last_modified',
|
||||
'full_name',
|
||||
]),
|
||||
desc: record.fields?.description || '',
|
||||
thumb_image_url: _.get(record.fields, 'thumb_image[0].url', '/Images/package-thumb-nolabel3.jpg')
|
||||
} as AirtablePackage;
|
||||
});
|
||||
/**
|
||||
* // SAMPLE RECORD SHAPE w/ thumb_image is uploaded
|
||||
{
|
||||
slug: 'unicode_org',
|
||||
name: 'unicode.org',
|
||||
full_name: 'unicode.org',
|
||||
homepage: 'https://unicode.org',
|
||||
version: '71.1.1',
|
||||
last_modified: '2022-09-26T19:46:25.000Z',
|
||||
thumb_image: [
|
||||
{
|
||||
id: 'attQVgaRUXOYinsWy',
|
||||
width: 640,
|
||||
height: 534,
|
||||
url: 'https://dl.airtable.com/.attachments/f2465c36a0060919368e2f53305694f9/cfab76a8/gen-art-1.png',
|
||||
filename: 'gen-art-1.png',
|
||||
size: 184878,
|
||||
type: 'image/png',
|
||||
thumbnails: [Object]
|
||||
}
|
||||
]
|
||||
}
|
||||
TODO IMAGE UPLOAD to S3/CDN:
|
||||
if thumb_image_url is empty
|
||||
get thumb_image data
|
||||
upload to s3
|
||||
update thumb_image_url in airtable
|
||||
*/
|
||||
return packages;
|
||||
const packages: AirtablePackage[] = allRecords.map((record) => {
|
||||
return {
|
||||
airtable_record_id: record.id,
|
||||
..._.pick(record.fields, [
|
||||
'slug',
|
||||
'homepage',
|
||||
'maintainer',
|
||||
'name',
|
||||
'version',
|
||||
'last_modified',
|
||||
'full_name',
|
||||
]),
|
||||
maintainer: record.fields?.maintainer || '',
|
||||
desc: record.fields?.description || '',
|
||||
thumb_image_url: _.get(record.fields, 'thumb_image[0].url', '/Images/package-thumb-nolabel3.jpg')
|
||||
} as AirtablePackage;
|
||||
});
|
||||
/**
|
||||
* // SAMPLE RECORD SHAPE w/ thumb_image is uploaded
|
||||
{
|
||||
slug: 'unicode_org',
|
||||
name: 'unicode.org',
|
||||
full_name: 'unicode.org',
|
||||
homepage: 'https://unicode.org',
|
||||
version: '71.1.1',
|
||||
last_modified: '2022-09-26T19:46:25.000Z',
|
||||
thumb_image: [
|
||||
{
|
||||
id: 'attQVgaRUXOYinsWy',
|
||||
width: 640,
|
||||
height: 534,
|
||||
url: 'https://dl.airtable.com/.attachments/f2465c36a0060919368e2f53305694f9/cfab76a8/gen-art-1.png',
|
||||
filename: 'gen-art-1.png',
|
||||
size: 184878,
|
||||
type: 'image/png',
|
||||
thumbnails: [Object]
|
||||
}
|
||||
]
|
||||
}
|
||||
TODO IMAGE UPLOAD to S3/CDN:
|
||||
if thumb_image_url is empty
|
||||
get thumb_image data
|
||||
upload to s3
|
||||
update thumb_image_url in airtable
|
||||
*/
|
||||
return packages;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import S3 from 'aws-sdk/clients/s3';
|
||||
import { compareVersions, validate } from 'compare-versions';
|
||||
|
||||
import _ from 'lodash';
|
||||
import type { S3Package } from './types';
|
||||
|
||||
const Bucket = process.env.AWS_DIST_BUCKET;
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
export interface S3Package {
|
||||
slug: string,
|
||||
version: string,
|
||||
full_name: string,
|
||||
name: string,
|
||||
maintainer: string,
|
||||
homepage: string,
|
||||
// key: string,
|
||||
last_modified: Date | string,
|
||||
slug: string,
|
||||
version: string,
|
||||
full_name: string,
|
||||
name: string,
|
||||
maintainer: string,
|
||||
homepage: string,
|
||||
// key: string,
|
||||
last_modified: Date | string,
|
||||
}
|
||||
|
||||
export type AirtablePackage = S3Package & {
|
||||
airtable_record_id: string,
|
||||
thumb_image_url: string,
|
||||
desc: string,
|
||||
airtable_record_id: string,
|
||||
thumb_image_url: string,
|
||||
desc: string,
|
||||
}
|
||||
|
||||
export type Package = Omit<AirtablePackage, 'airtable_record_id'> & {
|
||||
airtable_record_id?: string,
|
||||
installs: number,
|
||||
airtable_record_id?: string,
|
||||
installs: number,
|
||||
}
|
Loading…
Reference in a new issue