アニメーション画像を無効にする際、サーバーサイドではなくクライアントサイドでURLを変更するように

This commit is contained in:
syuilo
2019-02-05 03:51:54 +09:00
parent f014b7ae0e
commit 861302f0fd
14 changed files with 40 additions and 56 deletions

View File

@ -0,0 +1,9 @@
import { url as instanceUrl } from '../../config';
export function getStaticImageUrl(url: string): string {
const u = new URL(url);
const dummy = `${u.host}${u.pathname}`; // 拡張子がないとキャッシュしてくれないCDNがあるので
let result = `${instanceUrl}/proxy/${dummy}?url=${encodeURIComponent(u.href)}`;
result += '&static=1';
return result;
}

View File

@ -15,6 +15,7 @@
<script lang="ts">
import Vue from 'vue';
import { getStaticImageUrl } from '../../../common/scripts/get-static-image-url';
export default Vue.extend({
props: {
@ -47,6 +48,11 @@ export default Vue.extend({
borderRadius: this.$store.state.settings.circleIcons ? '100%' : null
};
},
url(): string {
return this.$store.state.device.doNotAutoplayAnimation
? getStaticImageUrl(this.user.avatarUrl)
: this.user.avatarUrl;
},
icon(): any {
return {
backgroundColor: this.lightmode
@ -54,7 +60,7 @@ export default Vue.extend({
: this.user.avatarColor && this.user.avatarColor.length == 3
? `rgb(${this.user.avatarColor.join(',')})`
: null,
backgroundImage: this.lightmode ? null : `url(${this.user.avatarUrl})`,
backgroundImage: this.lightmode ? null : `url(${this.url})`,
borderRadius: this.$store.state.settings.circleIcons ? '100%' : null
};
}

View File

@ -9,6 +9,7 @@
import Vue from 'vue';
// スクリプトサイズがデカい
//import { lib } from 'emojilib';
import { getStaticImageUrl } from '../../../common/scripts/get-static-image-url';
export default Vue.extend({
props: {
@ -54,7 +55,9 @@ export default Vue.extend({
const customEmoji = this.customEmojis.find(x => x.name == this.name);
if (customEmoji) {
this.customEmoji = customEmoji;
this.url = customEmoji.url;
this.url = this.$store.state.device.doNotAutoplayAnimation
? getStaticImageUrl(customEmoji.url)
: customEmoji.url;
} else {
//const emoji = lib[this.name];
//if (emoji) {

View File

@ -17,6 +17,7 @@
import Vue from 'vue';
import i18n from '../../../i18n';
import ImageViewer from './image-viewer.vue';
import { getStaticImageUrl } from '../../../common/scripts/get-static-image-url';
export default Vue.extend({
i18n: i18n('common/views/components/media-image.vue'),
@ -36,7 +37,11 @@ export default Vue.extend({
}
computed: {
style(): any {
let url = `url(${this.image.thumbnailUrl})`;
let url = `url(${
this.$store.state.device.doNotAutoplayAnimation
? getStaticImageUrl(this.image.thumbnailUrl)
: this.image.thumbnailUrl
})`;
if (this.$store.state.device.loadRemoteMedia || this.$store.state.device.lightmode) {
url = null;

View File

@ -518,8 +518,8 @@ export default Vue.extend({
},
doNotAutoplayAnimation: {
get() { return !!this.$store.state.settings.doNotAutoplayAnimation; },
set(value) { this.$store.dispatch('settings/set', { key: 'doNotAutoplayAnimation', value }); }
get() { return this.$store.state.device.doNotAutoplayAnimation; },
set(value) { this.$store.commit('device/set', { key: 'doNotAutoplayAnimation', value }); }
},
remainDeletedNote: {

View File

@ -315,8 +315,8 @@ export default Vue.extend({
},
doNotAutoplayAnimation: {
get() { return !!this.$store.state.settings.doNotAutoplayAnimation; },
set(value) { this.$store.dispatch('settings/set', { key: 'doNotAutoplayAnimation', value }); }
get() { return this.$store.state.device.doNotAutoplayAnimation; },
set(value) { this.$store.commit('device/set', { key: 'doNotAutoplayAnimation', value }); }
},
showReplyTarget: {

View File

@ -3,7 +3,6 @@ import createPersistedState from 'vuex-persistedstate';
import * as nestedProperty from 'nested-property';
import MiOS from './mios';
import { hostname } from './config';
import { erase } from '../../prelude/array';
import getNoteSummary from '../../misc/get-note-summary';
@ -70,7 +69,8 @@ const defaultDeviceSettings = {
mobileNotificationPosition: 'bottom',
deckTemporaryColumn: null,
deckDefault: false,
useOsDefaultEmojis: false
useOsDefaultEmojis: false,
doNotAutoplayAnimation: false
};
export default (os: MiOS) => new Vuex.Store({