1
0
Fork 0

chore(backend): Import user avatars but not sets (for now)

This commit is contained in:
joostdecock 2023-08-13 18:57:07 +02:00
parent 6451222b2b
commit e36fbad721
3 changed files with 14 additions and 5 deletions

View file

@ -76,7 +76,6 @@ const html = mustache.render(
*/
const batches = splitArray(users, 45)
let i = 0
const total = batches.length
batches.forEach((batch, i) => {
/*

View file

@ -1289,7 +1289,6 @@ const migrateUser = (v2) => {
* This is a special route not available for API users
*/
UserModel.prototype.import = async function (user) {
let created = 0
if (user.status === 'active') {
const data = migrateUser(user)
if (user.consent.profile) data.consent++
@ -1303,7 +1302,7 @@ UserModel.prototype.import = async function (user) {
/*
* Skip images for now
*/
if (false && data.img) {
if (data.img) {
/*
* Figure out what image to grab from the FreeSewing v2 backend server
*/
@ -1333,7 +1332,6 @@ UserModel.prototype.import = async function (user) {
}
try {
await this.createRecord(data)
created++
} catch (err) {
log.warn(err, 'Could not create user record')
console.log(user)

View file

@ -88,8 +88,20 @@ export async function importImage(props, isTest = false) {
// Bypass slow ass upload when testing import
if (!config.import) return `default-avatar`
// Only upload user images for now
if (props.id.slice(0, 5) !== 'user-') return `default-avatar`
const form = getFormData(props)
await axios.post(config.api, form, { headers })
/*
* The image may already exist, so swallow the error
*/
try {
await axios.post(config.api, form, { headers })
} catch {
// Do nothing
}
console.log('Imported img', props.id)
return props.id
}