Upload profile pic during user creation
This commit is contained in:
parent
95f48b24ba
commit
219a1aa751
1 changed files with 23 additions and 1 deletions
24
functions.js
24
functions.js
|
@ -5,6 +5,8 @@ const getPost = require('mediumexporter').getPost
|
||||||
const { createClient } = require('webdav')
|
const { createClient } = require('webdav')
|
||||||
const readline = require('readline')
|
const readline = require('readline')
|
||||||
|
|
||||||
|
const MEDIUM_IMG_CDN = 'https://miro.medium.com/fit/c/'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function [fetchFromMedium]
|
* function [fetchFromMedium]
|
||||||
* @returns [string] status
|
* @returns [string] status
|
||||||
|
@ -177,6 +179,26 @@ const generateUserData = async (mediumUsername, email) => {
|
||||||
console.debug(`Name: ${json.payload.user.name}`)
|
console.debug(`Name: ${json.payload.user.name}`)
|
||||||
console.debug(`Bio: ${json.payload.user.bio}`)
|
console.debug(`Bio: ${json.payload.user.bio}`)
|
||||||
|
|
||||||
|
// Download and upload image
|
||||||
|
|
||||||
|
let imageId = json.payload.user.imageId
|
||||||
|
console.log(`Image: ${imageId}`)
|
||||||
|
|
||||||
|
let imagePath = MEDIUM_IMG_CDN + '256/256/' + imageId
|
||||||
|
let filetype = imageId.split('.')[imageId.split('.').length - 1]
|
||||||
|
let fileName = `${mediumUsername}.${filetype}`
|
||||||
|
let filePath = path.join(process.env.PWD, fileName)
|
||||||
|
|
||||||
|
console.log(`Fetching: ${imagePath}`)
|
||||||
|
|
||||||
|
const response = await (await r2.get(imagePath).response).buffer()
|
||||||
|
await fs.writeFileSync(filePath, response, 'base64')
|
||||||
|
|
||||||
|
console.log("Uploading to server")
|
||||||
|
|
||||||
|
await uploadDav(path.join(process.env.WEBDAV_PATH_PREFIX,'avatars'),
|
||||||
|
filePath)
|
||||||
|
|
||||||
// Generate Ghost JSON
|
// Generate Ghost JSON
|
||||||
|
|
||||||
const ghostData = {
|
const ghostData = {
|
||||||
|
@ -188,6 +210,7 @@ const generateUserData = async (mediumUsername, email) => {
|
||||||
bio: json.payload.user.bio,
|
bio: json.payload.user.bio,
|
||||||
email: email,
|
email: email,
|
||||||
name: json.payload.user.name,
|
name: json.payload.user.name,
|
||||||
|
profile_image: process.env.WEBDAV_UPLOADED_PATH_PREFIX + '/avatars/' + fileName
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -197,7 +220,6 @@ const generateUserData = async (mediumUsername, email) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return(JSON.stringify(ghostData))
|
return(JSON.stringify(ghostData))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue