From c547eafe195c4392dc461064f31fe410ee3e16fa Mon Sep 17 00:00:00 2001 From: neil Date: Thu, 20 Oct 2022 08:53:27 +0800 Subject: [PATCH] fix types and default placeholder values --- lambdas/src/libs/airtable.ts | 103 ++++++++++++++++--------------- lambdas/src/libs/dist_tea_xyz.ts | 2 +- lambdas/src/libs/types.ts | 26 ++++---- 3 files changed, 66 insertions(+), 65 deletions(-) diff --git a/lambdas/src/libs/airtable.ts b/lambdas/src/libs/airtable.ts index bb78ec4..b267798 100644 --- a/lambdas/src/libs/airtable.ts +++ b/lambdas/src/libs/airtable.ts @@ -6,56 +6,57 @@ import type { AirtablePackage } from './types'; const airtablePackagesBase = base(process.env.AIRTABLE_PACKAGES_BASE); -export const getAllAirtablePackages = async () : Promise => { - const allRecords = await airtablePackagesBase('packages') - .select({ - maxRecords: 100, - view: '_api' - }).all(); +export const getAllAirtablePackages = async (): Promise => { + 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; } \ No newline at end of file diff --git a/lambdas/src/libs/dist_tea_xyz.ts b/lambdas/src/libs/dist_tea_xyz.ts index 1a5c8ef..f22099e 100644 --- a/lambdas/src/libs/dist_tea_xyz.ts +++ b/lambdas/src/libs/dist_tea_xyz.ts @@ -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; diff --git a/lambdas/src/libs/types.ts b/lambdas/src/libs/types.ts index 69c51a6..09d2856 100644 --- a/lambdas/src/libs/types.ts +++ b/lambdas/src/libs/types.ts @@ -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 & { - airtable_record_id?: string, - installs: number, + airtable_record_id?: string, + installs: number, } \ No newline at end of file