Skip to content

Commit

Permalink
ref(cleanup)
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Stuart <hi@jessestuart.com>
  • Loading branch information
jessestuart committed Apr 17, 2019
1 parent ad30223 commit 467ce51
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 57 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
"license": "MIT",
"main": "index.js",
"peerDependencies": {
"gatsby": "^2.3.22",
"gatsby-image": "^2.0.38",
"gatsby-source-filesystem": "^2.0.29",
"gatsby": "^2",
"gatsby-image": "^2",
"gatsby-source-filesystem": "^2",
"react": "^16"
},
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions src/set-fields-on-graphql-node-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import exif from 'exif-parser'

import fs from 'fs'

import ExifDataType from './types/exif-data'
import ExifData from './types/exif-data'
import S3ImageAssetNode from './types/s3-image-asset-node'

const {
Expand All @@ -14,7 +14,7 @@ const {
GraphQLString,
} = require('gatsby/graphql')

export const resolveExifData = (image: S3ImageAssetNode): ExifDataType => {
export const resolveExifData = (image: S3ImageAssetNode): ExifData => {
const file = fs.readFileSync(image.absolutePath)
const tags = exif.create(file).parse().tags
const timestamp = tags.DateTimeOriginal * 1000
Expand All @@ -40,9 +40,9 @@ interface ExtendNodeTypeOptions {
}
}

export default ({ type }: ExtendNodeTypeOptions) => {
export default ({ type }: ExtendNodeTypeOptions): Promise<any> => {
if (type.name !== 'S3ImageAsset') {
return
return Promise.resolve()
}

return Promise.resolve({
Expand Down
85 changes: 37 additions & 48 deletions src/source-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,57 +49,46 @@ export const sourceNodes = async (

return await Promise.all(
_.compact(
s3Entities.map(async (entity: S3.Object) => {
if (!isImage(entity)) {
return null
}

const url: string | undefined = constructS3UrlForAsset({
bucketName,
domain,
key: entity.Key,
protocol,
})
if (!url) {
return null
}

// const entityData = {
// bucketName,
// cache,
// createNode,
// createNodeId,
// domain,
// entity,
// localFile___NODE: null,
// protocol,
// url,
// store,
// }
s3Entities.map(
async (entity: S3.Object): Promise<void> => {
if (!isImage(entity)) {
return
}

try {
const fileNode = await createS3RemoteFileNode({
cache,
createNode,
createNodeId,
url,
store,
const url: string | undefined = constructS3UrlForAsset({
bucketName,
domain,
key: entity.Key,
protocol,
})
if (!fileNode) {
return null
if (!url) {
return
}

return await createS3ImageAssetNode({
createNode,
createNodeId,
entity,
fileNode,
url,
})
} catch (err) {
Promise.reject(err)
try {
const fileNode = await createS3RemoteFileNode({
cache,
createNode,
createNodeId,
url,
store,
})
if (!fileNode) {
return
}

return await createS3ImageAssetNode({
createNode,
createNodeId,
entity,
fileNode,
url,
})
} catch (err) {
Promise.reject(err)
}
}
})
)
)
)
}
Expand Down Expand Up @@ -136,7 +125,7 @@ const createS3ImageAssetNode = async ({
entity: S3.Object
fileNode: { absolutePath: string; id: string }
url: string
}): Promise<any> => {
}): Promise<void> => {
const { Key, ETag } = entity
// TODO: Use the `mime-types` lib to populate this dynamically.
// const ContentType = 'image/jpeg'
Expand All @@ -150,7 +139,7 @@ const createS3ImageAssetNode = async ({
await createNode({
...entity,
absolutePath: fileNode.absolutePath,
children: fileNodeId,
children: [fileNodeId],
ETag: objectHash,
id: createNodeId(objectHash),
Key,
Expand Down
2 changes: 0 additions & 2 deletions src/types/exif-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,3 @@ export enum ExifFields {
Model,
ShutterSpeedValue,
}

console.log(ExifFields)

0 comments on commit 467ce51

Please sign in to comment.