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 password from './passwordMiddleware'
|
||||||
import softDelete from './softDeleteMiddleware'
|
import softDelete from './softDeleteMiddleware'
|
||||||
import sluggify from './sluggifyMiddleware'
|
import sluggify from './sluggifyMiddleware'
|
||||||
import fixImageUrls from './fixImageUrlsMiddleware'
|
|
||||||
import excerpt from './excerptMiddleware'
|
import excerpt from './excerptMiddleware'
|
||||||
import dateTime from './dateTimeMiddleware'
|
import dateTime from './dateTimeMiddleware'
|
||||||
import xss from './xssMiddleware'
|
import xss from './xssMiddleware'
|
||||||
@ -25,7 +24,6 @@ export default schema => {
|
|||||||
excerpt: excerpt,
|
excerpt: excerpt,
|
||||||
notifications: notifications,
|
notifications: notifications,
|
||||||
xss: xss,
|
xss: xss,
|
||||||
fixImageUrls: fixImageUrls,
|
|
||||||
softDelete: softDelete,
|
softDelete: softDelete,
|
||||||
user: user,
|
user: user,
|
||||||
includedFields: includedFields,
|
includedFields: includedFields,
|
||||||
@ -42,7 +40,6 @@ export default schema => {
|
|||||||
'excerpt',
|
'excerpt',
|
||||||
'notifications',
|
'notifications',
|
||||||
'xss',
|
'xss',
|
||||||
'fixImageUrls',
|
|
||||||
'softDelete',
|
'softDelete',
|
||||||
'user',
|
'user',
|
||||||
'includedFields',
|
'includedFields',
|
||||||
|
|||||||
@ -45,7 +45,7 @@ MERGE(b:Badge {id: badge._id["$oid"]})
|
|||||||
ON CREATE SET
|
ON CREATE SET
|
||||||
b.key = badge.key,
|
b.key = badge.key,
|
||||||
b.type = badge.type,
|
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.status = badge.status,
|
||||||
b.createdAt = badge.createdAt.`$date`,
|
b.createdAt = badge.createdAt.`$date`,
|
||||||
b.updatedAt = badge.updatedAt.`$date`
|
b.updatedAt = badge.updatedAt.`$date`
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
[?] unique: true, // Unique value is not enforced in Nitro?
|
[?] unique: true, // Unique value is not enforced in Nitro?
|
||||||
[-] index: true
|
[-] index: true
|
||||||
},
|
},
|
||||||
[ ] type: {
|
[ ] type: { // db.getCollection('contributions').distinct('type') -> 'DELETED', 'cando', 'post'
|
||||||
[ ] type: String,
|
[ ] type: String,
|
||||||
[ ] required: true,
|
[ ] required: true,
|
||||||
[-] index: true
|
[-] index: true
|
||||||
@ -50,7 +50,7 @@
|
|||||||
[?] required: true // Not required in Nitro
|
[?] required: true // Not required in Nitro
|
||||||
},
|
},
|
||||||
[ ] hasMore: { type: Boolean },
|
[ ] hasMore: { type: Boolean },
|
||||||
[?] teaserImg: { type: String }, // Path is incorrect in Nitro
|
[X] teaserImg: { type: String },
|
||||||
[ ] language: {
|
[ ] language: {
|
||||||
[ ] type: String,
|
[ ] type: String,
|
||||||
[ ] required: true,
|
[ ] required: true,
|
||||||
@ -131,7 +131,7 @@ MERGE (p:Post {id: post._id["$oid"]})
|
|||||||
ON CREATE SET
|
ON CREATE SET
|
||||||
p.title = post.title,
|
p.title = post.title,
|
||||||
p.slug = post.slug,
|
p.slug = post.slug,
|
||||||
p.image = post.teaserImg,
|
p.image = replace(post.teaserImg, 'https://api-alpha.human-connection.org', ''),
|
||||||
p.content = post.content,
|
p.content = post.content,
|
||||||
p.contentExcerpt = post.contentExcerpt,
|
p.contentExcerpt = post.contentExcerpt,
|
||||||
p.visibility = toLower(post.visibility),
|
p.visibility = toLower(post.visibility),
|
||||||
|
|||||||
@ -49,8 +49,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
[ ] timezone: { type: String },
|
[ ] timezone: { type: String },
|
||||||
[?] avatar: { type: String }, // Path is incorrect in Nitro
|
[X] avatar: { type: String },
|
||||||
[?] coverImg: { type: String }, // Path is incorrect in Nitro, was not modeled in latest Nitro - do we want this?
|
[X] coverImg: { type: String },
|
||||||
[ ] doiToken: { type: String },
|
[ ] doiToken: { type: String },
|
||||||
[ ] confirmedAt: { type: Date },
|
[ ] confirmedAt: { type: Date },
|
||||||
[?] badgeIds: [], // Verify this is working properly
|
[?] badgeIds: [], // Verify this is working properly
|
||||||
@ -102,8 +102,8 @@ u.name = user.name,
|
|||||||
u.slug = user.slug,
|
u.slug = user.slug,
|
||||||
u.email = user.email,
|
u.email = user.email,
|
||||||
u.password = user.password,
|
u.password = user.password,
|
||||||
u.avatar = user.avatar,
|
u.avatar = replace(user.avatar, 'https://api-alpha.human-connection.org', ''),
|
||||||
u.coverImg = user.coverImg,
|
u.coverImg = replace(user.coverImg, 'https://api-alpha.human-connection.org', ''),
|
||||||
u.wasInvited = user.wasInvited,
|
u.wasInvited = user.wasInvited,
|
||||||
u.wasSeeded = user.wasSeeded,
|
u.wasSeeded = user.wasSeeded,
|
||||||
u.role = toLower(user.role),
|
u.role = toLower(user.role),
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
"!**/?(*.)+(spec|test).js?(x)"
|
"!**/?(*.)+(spec|test).js?(x)"
|
||||||
],
|
],
|
||||||
"coverageReporters": [
|
"coverageReporters": [
|
||||||
|
"text",
|
||||||
"lcov"
|
"lcov"
|
||||||
],
|
],
|
||||||
"transform": {
|
"transform": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user