fix types and default placeholder values

This commit is contained in:
neil 2022-10-20 08:53:27 +08:00
parent 201fc97544
commit c547eafe19
3 changed files with 66 additions and 65 deletions

View file

@ -6,56 +6,57 @@ import type { AirtablePackage } from './types';
const airtablePackagesBase = base(process.env.AIRTABLE_PACKAGES_BASE); const airtablePackagesBase = base(process.env.AIRTABLE_PACKAGES_BASE);
export const getAllAirtablePackages = async () : Promise<AirtablePackage[]> => { export const getAllAirtablePackages = async (): Promise<AirtablePackage[]> => {
const allRecords = await airtablePackagesBase('packages') const allRecords = await airtablePackagesBase('packages')
.select({ .select({
maxRecords: 100, maxRecords: 100,
view: '_api' view: '_api'
}).all(); }).all();
const packages: AirtablePackage[] = allRecords.map((record) => { const packages: AirtablePackage[] = allRecords.map((record) => {
return { return {
airtable_record_id: record.id, airtable_record_id: record.id,
..._.pick(record.fields, [ ..._.pick(record.fields, [
'slug', 'slug',
'homepage', 'homepage',
'maintainer', 'maintainer',
'name', 'name',
'version', 'version',
'last_modified', 'last_modified',
'full_name', 'full_name',
]), ]),
desc: record.fields?.description || '', maintainer: record.fields?.maintainer || '',
thumb_image_url: _.get(record.fields, 'thumb_image[0].url', '/Images/package-thumb-nolabel3.jpg') desc: record.fields?.description || '',
} as AirtablePackage; 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 /**
{ * // SAMPLE RECORD SHAPE w/ thumb_image is uploaded
slug: 'unicode_org', {
name: 'unicode.org', slug: 'unicode_org',
full_name: 'unicode.org', name: 'unicode.org',
homepage: 'https://unicode.org', full_name: 'unicode.org',
version: '71.1.1', homepage: 'https://unicode.org',
last_modified: '2022-09-26T19:46:25.000Z', version: '71.1.1',
thumb_image: [ last_modified: '2022-09-26T19:46:25.000Z',
{ thumb_image: [
id: 'attQVgaRUXOYinsWy', {
width: 640, id: 'attQVgaRUXOYinsWy',
height: 534, width: 640,
url: 'https://dl.airtable.com/.attachments/f2465c36a0060919368e2f53305694f9/cfab76a8/gen-art-1.png', height: 534,
filename: 'gen-art-1.png', url: 'https://dl.airtable.com/.attachments/f2465c36a0060919368e2f53305694f9/cfab76a8/gen-art-1.png',
size: 184878, filename: 'gen-art-1.png',
type: 'image/png', size: 184878,
thumbnails: [Object] type: 'image/png',
} thumbnails: [Object]
] }
} ]
TODO IMAGE UPLOAD to S3/CDN: }
if thumb_image_url is empty TODO IMAGE UPLOAD to S3/CDN:
get thumb_image data if thumb_image_url is empty
upload to s3 get thumb_image data
update thumb_image_url in airtable upload to s3
*/ update thumb_image_url in airtable
return packages; */
return packages;
} }

View file

@ -1,6 +1,6 @@
import S3 from 'aws-sdk/clients/s3'; import S3 from 'aws-sdk/clients/s3';
import { compareVersions, validate } from 'compare-versions'; import { compareVersions, validate } from 'compare-versions';
import _ from 'lodash';
import type { S3Package } from './types'; import type { S3Package } from './types';
const Bucket = process.env.AWS_DIST_BUCKET; const Bucket = process.env.AWS_DIST_BUCKET;

View file

@ -1,21 +1,21 @@
export interface S3Package { export interface S3Package {
slug: string, slug: string,
version: string, version: string,
full_name: string, full_name: string,
name: string, name: string,
maintainer: string, maintainer: string,
homepage: string, homepage: string,
// key: string, // key: string,
last_modified: Date | string, last_modified: Date | string,
} }
export type AirtablePackage = S3Package & { export type AirtablePackage = S3Package & {
airtable_record_id: string, airtable_record_id: string,
thumb_image_url: string, thumb_image_url: string,
desc: string, desc: string,
} }
export type Package = Omit<AirtablePackage, 'airtable_record_id'> & { export type Package = Omit<AirtablePackage, 'airtable_record_id'> & {
airtable_record_id?: string, airtable_record_id?: string,
installs: number, installs: number,
} }