mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge pull request #829 from Human-Connection/2019/kw24/fix_imported_img_urls
🍰 2019/kw24/fix_imported_img_urls
This commit is contained in:
commit
181b4b48e6
@ -1,51 +0,0 @@
|
||||
const legacyUrls = [
|
||||
'https://api-alpha.human-connection.org',
|
||||
'https://staging-api.human-connection.org',
|
||||
'http://localhost:3000',
|
||||
]
|
||||
|
||||
export const fixUrl = url => {
|
||||
legacyUrls.forEach(legacyUrl => {
|
||||
url = url.replace(legacyUrl, '')
|
||||
})
|
||||
if (!url.startsWith('/')) {
|
||||
url = `/${url}`
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
const checkUrl = thing => {
|
||||
return (
|
||||
thing &&
|
||||
typeof thing === 'string' &&
|
||||
legacyUrls.find(legacyUrl => {
|
||||
return thing.indexOf(legacyUrl) === 0
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export const fixImageURLs = (result, recursive) => {
|
||||
if (checkUrl(result)) {
|
||||
result = fixUrl(result)
|
||||
} else if (result && Array.isArray(result)) {
|
||||
result.forEach((res, index) => {
|
||||
result[index] = fixImageURLs(result[index], true)
|
||||
})
|
||||
} else if (result && typeof result === 'object') {
|
||||
Object.keys(result).forEach(key => {
|
||||
result[key] = fixImageURLs(result[key], true)
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default {
|
||||
Mutation: async (resolve, root, args, context, info) => {
|
||||
const result = await resolve(root, args, context, info)
|
||||
return fixImageURLs(result)
|
||||
},
|
||||
Query: async (resolve, root, args, context, info) => {
|
||||
let result = await resolve(root, args, context, info)
|
||||
return fixImageURLs(result)
|
||||
},
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
import { fixImageURLs } from './fixImageUrlsMiddleware'
|
||||
|
||||
describe('fixImageURLs', () => {
|
||||
describe('edge case: image url is exact match of legacy url', () => {
|
||||
it('replaces it with `/`', () => {
|
||||
const url = 'https://api-alpha.human-connection.org'
|
||||
expect(fixImageURLs(url)).toEqual('/')
|
||||
})
|
||||
})
|
||||
|
||||
describe('image url of legacy alpha', () => {
|
||||
it('removes domain', () => {
|
||||
const url =
|
||||
'https://api-alpha.human-connection.org/uploads/4bfaf9172c4ba03d7645108bbbd16f0a696a37d01eacd025fb131e5da61b15d9.png'
|
||||
expect(fixImageURLs(url)).toEqual(
|
||||
'/uploads/4bfaf9172c4ba03d7645108bbbd16f0a696a37d01eacd025fb131e5da61b15d9.png',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('image url of legacy staging', () => {
|
||||
it('removes domain', () => {
|
||||
const url =
|
||||
'https://staging-api.human-connection.org/uploads/1b3c39a24f27e2fb62b69074b2f71363b63b263f0c4574047d279967124c026e.jpeg'
|
||||
expect(fixImageURLs(url)).toEqual(
|
||||
'/uploads/1b3c39a24f27e2fb62b69074b2f71363b63b263f0c4574047d279967124c026e.jpeg',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('object', () => {
|
||||
it('returns untouched', () => {
|
||||
const object = { some: 'thing' }
|
||||
expect(fixImageURLs(object)).toEqual(object)
|
||||
})
|
||||
})
|
||||
|
||||
describe('some string', () => {
|
||||
it('returns untouched', () => {})
|
||||
const string = "Yeah I'm a String"
|
||||
expect(fixImageURLs(string)).toEqual(string)
|
||||
})
|
||||
})
|
||||
@ -3,7 +3,6 @@ import activityPub from './activityPubMiddleware'
|
||||
import password from './passwordMiddleware'
|
||||
import softDelete from './softDeleteMiddleware'
|
||||
import sluggify from './sluggifyMiddleware'
|
||||
import fixImageUrls from './fixImageUrlsMiddleware'
|
||||
import excerpt from './excerptMiddleware'
|
||||
import dateTime from './dateTimeMiddleware'
|
||||
import xss from './xssMiddleware'
|
||||
@ -25,7 +24,6 @@ export default schema => {
|
||||
excerpt: excerpt,
|
||||
notifications: notifications,
|
||||
xss: xss,
|
||||
fixImageUrls: fixImageUrls,
|
||||
softDelete: softDelete,
|
||||
user: user,
|
||||
includedFields: includedFields,
|
||||
@ -42,7 +40,6 @@ export default schema => {
|
||||
'excerpt',
|
||||
'notifications',
|
||||
'xss',
|
||||
'fixImageUrls',
|
||||
'softDelete',
|
||||
'user',
|
||||
'includedFields',
|
||||
|
||||
@ -45,7 +45,7 @@ MERGE(b:Badge {id: badge._id["$oid"]})
|
||||
ON CREATE SET
|
||||
b.key = badge.key,
|
||||
b.type = badge.type,
|
||||
b.icon = badge.image.path,
|
||||
b.icon = replace(badge.image.path, 'https://api-alpha.human-connection.org', ''),
|
||||
b.status = badge.status,
|
||||
b.createdAt = badge.createdAt.`$date`,
|
||||
b.updatedAt = badge.updatedAt.`$date`
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
[?] unique: true, // Unique value is not enforced in Nitro?
|
||||
[-] index: true
|
||||
},
|
||||
[ ] type: {
|
||||
[ ] type: { // db.getCollection('contributions').distinct('type') -> 'DELETED', 'cando', 'post'
|
||||
[ ] type: String,
|
||||
[ ] required: true,
|
||||
[-] index: true
|
||||
@ -50,7 +50,7 @@
|
||||
[?] required: true // Not required in Nitro
|
||||
},
|
||||
[ ] hasMore: { type: Boolean },
|
||||
[?] teaserImg: { type: String }, // Path is incorrect in Nitro
|
||||
[X] teaserImg: { type: String },
|
||||
[ ] language: {
|
||||
[ ] type: String,
|
||||
[ ] required: true,
|
||||
@ -131,7 +131,7 @@ MERGE (p:Post {id: post._id["$oid"]})
|
||||
ON CREATE SET
|
||||
p.title = post.title,
|
||||
p.slug = post.slug,
|
||||
p.image = post.teaserImg,
|
||||
p.image = replace(post.teaserImg, 'https://api-alpha.human-connection.org', ''),
|
||||
p.content = post.content,
|
||||
p.contentExcerpt = post.contentExcerpt,
|
||||
p.visibility = toLower(post.visibility),
|
||||
|
||||
@ -49,8 +49,8 @@
|
||||
}
|
||||
},
|
||||
[ ] timezone: { type: String },
|
||||
[?] avatar: { type: String }, // Path is incorrect in Nitro
|
||||
[?] coverImg: { type: String }, // Path is incorrect in Nitro, was not modeled in latest Nitro - do we want this?
|
||||
[X] avatar: { type: String },
|
||||
[X] coverImg: { type: String },
|
||||
[ ] doiToken: { type: String },
|
||||
[ ] confirmedAt: { type: Date },
|
||||
[?] badgeIds: [], // Verify this is working properly
|
||||
@ -102,8 +102,8 @@ u.name = user.name,
|
||||
u.slug = user.slug,
|
||||
u.email = user.email,
|
||||
u.password = user.password,
|
||||
u.avatar = user.avatar,
|
||||
u.coverImg = user.coverImg,
|
||||
u.avatar = replace(user.avatar, 'https://api-alpha.human-connection.org', ''),
|
||||
u.coverImg = replace(user.coverImg, 'https://api-alpha.human-connection.org', ''),
|
||||
u.wasInvited = user.wasInvited,
|
||||
u.wasSeeded = user.wasSeeded,
|
||||
u.role = toLower(user.role),
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
"!**/?(*.)+(spec|test).js?(x)"
|
||||
],
|
||||
"coverageReporters": [
|
||||
"text",
|
||||
"lcov"
|
||||
],
|
||||
"transform": {
|
||||
@ -110,4 +111,4 @@
|
||||
"vue-jest": "~3.0.4",
|
||||
"vue-svg-loader": "~0.12.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user