mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Merge pull request #693 from Human-Connection/689-fix_broken_image_urls_after_upload
689 fix broken image urls after upload
This commit is contained in:
commit
9c53e135c8
69
webapp/components/Avatar/Avatar.spec.js
Normal file
69
webapp/components/Avatar/Avatar.spec.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { mount, createLocalVue } from '@vue/test-utils'
|
||||||
|
import Styleguide from '@human-connection/styleguide'
|
||||||
|
import Avatar from './Avatar.vue'
|
||||||
|
|
||||||
|
const localVue = createLocalVue()
|
||||||
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
|
describe('Avatar.vue', () => {
|
||||||
|
let propsData = {}
|
||||||
|
|
||||||
|
const Wrapper = () => {
|
||||||
|
return mount(Avatar, { propsData, localVue })
|
||||||
|
}
|
||||||
|
|
||||||
|
it('renders no image', () => {
|
||||||
|
expect(
|
||||||
|
Wrapper()
|
||||||
|
.find('img')
|
||||||
|
.exists(),
|
||||||
|
).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders an icon', () => {
|
||||||
|
expect(
|
||||||
|
Wrapper()
|
||||||
|
.find('.ds-icon')
|
||||||
|
.exists(),
|
||||||
|
).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('given a user', () => {
|
||||||
|
describe('with a relative avatar url', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
propsData = {
|
||||||
|
user: {
|
||||||
|
avatar: '/avatar.jpg',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('adds a prefix to load the image from the uploads service', () => {
|
||||||
|
expect(
|
||||||
|
Wrapper()
|
||||||
|
.find('img')
|
||||||
|
.attributes('src'),
|
||||||
|
).toBe('/api/avatar.jpg')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('with an absolute avatar url', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
propsData = {
|
||||||
|
user: {
|
||||||
|
avatar: 'http://lorempixel.com/640/480/animals',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('keeps the avatar URL as is', () => {
|
||||||
|
// e.g. our seeds have absolute image URLs
|
||||||
|
expect(
|
||||||
|
Wrapper()
|
||||||
|
.find('img')
|
||||||
|
.attributes('src'),
|
||||||
|
).toBe('http://lorempixel.com/640/480/animals')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
33
webapp/components/Avatar/Avatar.vue
Normal file
33
webapp/components/Avatar/Avatar.vue
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<template>
|
||||||
|
<ds-avatar
|
||||||
|
:image="avatarUrl"
|
||||||
|
:name="userName"
|
||||||
|
class="avatar"
|
||||||
|
:size="size"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'HcAvatar',
|
||||||
|
props: {
|
||||||
|
user: { type: Object, default: null },
|
||||||
|
size: { type: String, default: 'small' },
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
avatarUrl() {
|
||||||
|
const { avatar: imageSrc } = this.user || {}
|
||||||
|
if (!imageSrc) return imageSrc
|
||||||
|
return imageSrc.startsWith('/') ? imageSrc.replace('/', '/api/') : imageSrc
|
||||||
|
},
|
||||||
|
userName() {
|
||||||
|
const { name } = this.user || {}
|
||||||
|
// The name is used to display the initials in case
|
||||||
|
// the image cannot be loaded.
|
||||||
|
return name
|
||||||
|
// If the name is undefined, then our styleguide will
|
||||||
|
// display an icon for the anonymous user.
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@ -3,10 +3,7 @@
|
|||||||
<div
|
<div
|
||||||
style="display: inline-block; float: left; margin-right: 4px; height: 100%; vertical-align: middle;"
|
style="display: inline-block; float: left; margin-right: 4px; height: 100%; vertical-align: middle;"
|
||||||
>
|
>
|
||||||
<ds-avatar
|
<hc-avatar />
|
||||||
style="display: inline-block; vertical-align: middle;"
|
|
||||||
size="small"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div style="display: inline-block; height: 100%; vertical-align: middle;">
|
<div style="display: inline-block; height: 100%; vertical-align: middle;">
|
||||||
<b
|
<b
|
||||||
@ -36,11 +33,8 @@
|
|||||||
<div
|
<div
|
||||||
style="display: inline-block; float: left; margin-right: 4px; height: 100%; vertical-align: middle;"
|
style="display: inline-block; float: left; margin-right: 4px; height: 100%; vertical-align: middle;"
|
||||||
>
|
>
|
||||||
<ds-avatar
|
<hc-avatar
|
||||||
:image="user.avatar"
|
:user="user"
|
||||||
:name="userName"
|
|
||||||
style="display: inline-block; vertical-align: middle;"
|
|
||||||
size="small"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: inline-block; height: 100%; vertical-align: middle;">
|
<div style="display: inline-block; height: 100%; vertical-align: middle;">
|
||||||
@ -143,6 +137,7 @@ import { mapGetters } from 'vuex'
|
|||||||
import HcRelativeDateTime from '~/components/RelativeDateTime'
|
import HcRelativeDateTime from '~/components/RelativeDateTime'
|
||||||
import HcFollowButton from '~/components/FollowButton'
|
import HcFollowButton from '~/components/FollowButton'
|
||||||
import HcBadges from '~/components/Badges'
|
import HcBadges from '~/components/Badges'
|
||||||
|
import HcAvatar from '~/components/Avatar/Avatar.vue'
|
||||||
import Dropdown from '~/components/Dropdown'
|
import Dropdown from '~/components/Dropdown'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -150,6 +145,7 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
HcRelativeDateTime,
|
HcRelativeDateTime,
|
||||||
HcFollowButton,
|
HcFollowButton,
|
||||||
|
HcAvatar,
|
||||||
HcBadges,
|
HcBadges,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
},
|
},
|
||||||
@ -183,12 +179,6 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.profile-avatar {
|
|
||||||
display: block;
|
|
||||||
margin: auto;
|
|
||||||
margin-top: -45px;
|
|
||||||
border: #fff 5px solid;
|
|
||||||
}
|
|
||||||
.user {
|
.user {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
@ -45,10 +45,8 @@
|
|||||||
:href="$router.resolve({name: 'profile-id-slug', params: {id: user.id, slug: user.slug}}).href"
|
:href="$router.resolve({name: 'profile-id-slug', params: {id: user.id, slug: user.slug}}).href"
|
||||||
@click.prevent="toggleMenu"
|
@click.prevent="toggleMenu"
|
||||||
>
|
>
|
||||||
<ds-avatar
|
<hc-avatar
|
||||||
:image="user.avatar"
|
:user="user"
|
||||||
:name="user.name"
|
|
||||||
size="small"
|
|
||||||
/>
|
/>
|
||||||
<ds-icon
|
<ds-icon
|
||||||
size="xx-small"
|
size="xx-small"
|
||||||
@ -123,6 +121,7 @@ import SearchInput from '~/components/SearchInput.vue'
|
|||||||
import Modal from '~/components/Modal'
|
import Modal from '~/components/Modal'
|
||||||
import NotificationMenu from '~/components/notifications/NotificationMenu'
|
import NotificationMenu from '~/components/notifications/NotificationMenu'
|
||||||
import Dropdown from '~/components/Dropdown'
|
import Dropdown from '~/components/Dropdown'
|
||||||
|
import HcAvatar from '~/components/Avatar/Avatar.vue'
|
||||||
import seo from '~/mixins/seo'
|
import seo from '~/mixins/seo'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -132,6 +131,7 @@ export default {
|
|||||||
SearchInput,
|
SearchInput,
|
||||||
Modal,
|
Modal,
|
||||||
NotificationMenu,
|
NotificationMenu,
|
||||||
|
HcAvatar,
|
||||||
},
|
},
|
||||||
mixins: [seo],
|
mixins: [seo],
|
||||||
data() {
|
data() {
|
||||||
|
|||||||
@ -18,10 +18,9 @@
|
|||||||
v-if="myProfile"
|
v-if="myProfile"
|
||||||
:user="user"
|
:user="user"
|
||||||
/>
|
/>
|
||||||
<ds-avatar
|
<hc-avatar
|
||||||
v-else
|
v-else
|
||||||
:image="user.avatar"
|
:user="user"
|
||||||
:name="userName"
|
|
||||||
class="profile-avatar"
|
class="profile-avatar"
|
||||||
size="x-large"
|
size="x-large"
|
||||||
/>
|
/>
|
||||||
@ -333,6 +332,7 @@ import HcLoadMore from '~/components/LoadMore.vue'
|
|||||||
import HcEmpty from '~/components/Empty.vue'
|
import HcEmpty from '~/components/Empty.vue'
|
||||||
import ContentMenu from '~/components/ContentMenu'
|
import ContentMenu from '~/components/ContentMenu'
|
||||||
import HcUpload from '~/components/Upload'
|
import HcUpload from '~/components/Upload'
|
||||||
|
import HcAvatar from '~/components/Avatar/Avatar.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -343,6 +343,7 @@ export default {
|
|||||||
HcBadges,
|
HcBadges,
|
||||||
HcLoadMore,
|
HcLoadMore,
|
||||||
HcEmpty,
|
HcEmpty,
|
||||||
|
HcAvatar,
|
||||||
ContentMenu,
|
ContentMenu,
|
||||||
HcUpload,
|
HcUpload,
|
||||||
},
|
},
|
||||||
@ -456,7 +457,7 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.profile-avatar {
|
.profile-avatar.ds-avatar {
|
||||||
display: block;
|
display: block;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
margin-top: -60px;
|
margin-top: -60px;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user