#269 reduce S3 usage - cloudfront
This commit is contained in:
parent
01d872cc1b
commit
9110ed957e
|
@ -29,6 +29,7 @@ AWS_REGION=
|
||||||
AWS_KEY=
|
AWS_KEY=
|
||||||
AWS_SECRET=
|
AWS_SECRET=
|
||||||
AWS_S3_BUCKET=
|
AWS_S3_BUCKET=
|
||||||
|
AWS_CLOUDFRONT_ID=
|
||||||
|
|
||||||
HCAPTCHA_SITEKEY=10000000-ffff-ffff-ffff-000000000001
|
HCAPTCHA_SITEKEY=10000000-ffff-ffff-ffff-000000000001
|
||||||
HCAPTCHA_SECRET=0x0000000000000000000000000000000000000000
|
HCAPTCHA_SECRET=0x0000000000000000000000000000000000000000
|
||||||
|
|
|
@ -331,7 +331,7 @@
|
||||||
this.$cookies.set('token', this.$store.state.token, cookieSettings);
|
this.$cookies.set('token', this.$store.state.token, cookieSettings);
|
||||||
},
|
},
|
||||||
async uploaded(ids) {
|
async uploaded(ids) {
|
||||||
await this.setAvatar(`${process.env.BUCKET}/images/${ids[0]}-avatar.png`);
|
await this.setAvatar(`${process.env.CLOUDFRONT}/images/${ids[0]}-avatar.png`);
|
||||||
},
|
},
|
||||||
async stopImpersonation() {
|
async stopImpersonation() {
|
||||||
this.$cookies.set('token', this.$cookies.get('impersonator'));
|
this.$cookies.set('token', this.$cookies.get('impersonator'));
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
-- Up
|
||||||
|
|
||||||
|
UPDATE users SET avatarSource = REPLACE(avatarSource, 'https://pronouns-page.s3-eu-west-1.amazonaws.com/images/', 'https://dclu0bpcdglik.cloudfront.net/images/')
|
||||||
|
WHERE avatarSource LIKE 'https://%/images/%';
|
||||||
|
|
||||||
|
-- Down
|
||||||
|
|
|
@ -176,6 +176,7 @@ export default {
|
||||||
LOCALES: locales,
|
LOCALES: locales,
|
||||||
FLAGS: buildFlags(),
|
FLAGS: buildFlags(),
|
||||||
BUCKET: `https://${process.env.AWS_S3_BUCKET}.s3-${process.env.AWS_REGION}.amazonaws.com`,
|
BUCKET: `https://${process.env.AWS_S3_BUCKET}.s3-${process.env.AWS_REGION}.amazonaws.com`,
|
||||||
|
CLOUDFRONT: `https://${process.env.AWS_CLOUDFRONT_ID}.cloudfront.net`,
|
||||||
STATS_FILE: process.env.STATS_FILE,
|
STATS_FILE: process.env.STATS_FILE,
|
||||||
HCAPTCHA_SITEKEY: process.env.HCAPTCHA_SITEKEY,
|
HCAPTCHA_SITEKEY: process.env.HCAPTCHA_SITEKEY,
|
||||||
ALL_LOCALES_URLS: process.env.ALL_LOCALES_URLS,
|
ALL_LOCALES_URLS: process.env.ALL_LOCALES_URLS,
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default ({ app, store }) => {
|
||||||
|
|
||||||
store.commit('setSpelling', app.$cookies.get('spelling') || 'traditional');
|
store.commit('setSpelling', app.$cookies.get('spelling') || 'traditional');
|
||||||
|
|
||||||
Vue.prototype.buildImageUrl = (imageId, size) => `${process.env.BUCKET}/images/${imageId}-${size}.png`
|
Vue.prototype.buildImageUrl = (imageId, size) => `${process.env.CLOUDFRONT}/images/${imageId}-${size}.png`
|
||||||
|
|
||||||
Vue.prototype.$loadScript = (name, src) => {
|
Vue.prototype.$loadScript = (name, src) => {
|
||||||
if (!process.client || document.querySelectorAll(`script.${name}-script`).length > 0) {
|
if (!process.client || document.querySelectorAll(`script.${name}-script`).length > 0) {
|
||||||
|
|
|
@ -16,9 +16,9 @@ async function cleanup() {
|
||||||
for (let row of await db.all(`
|
for (let row of await db.all(`
|
||||||
SELECT avatarSource
|
SELECT avatarSource
|
||||||
FROM users
|
FROM users
|
||||||
WHERE avatarSource LIKE 'https://pronouns-page.s3-eu-west-1.amazonaws.com/images/%'`
|
WHERE avatarSource LIKE 'https://%/images/%'`
|
||||||
)) {
|
)) {
|
||||||
avatars[row.avatarSource.match('https://pronouns-page.s3.eu-west-1.amazonaws.com/images/(.*)-thumb.png')[1]] = true;
|
avatars[row.avatarSource.match('https://[^/]+/images/(.*)-(?:thumb|avatar).png')[1]] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const flags = {};
|
const flags = {};
|
||||||
|
|
|
@ -11,8 +11,8 @@ import S3 from 'aws-sdk/clients/s3';
|
||||||
const sizes = {
|
const sizes = {
|
||||||
big: [1200, false],
|
big: [1200, false],
|
||||||
flag: [256, false],
|
flag: [256, false],
|
||||||
thumb: [128, true],
|
thumb: [192, true],
|
||||||
avatar: [96, true],
|
avatar: [144, true],
|
||||||
}
|
}
|
||||||
|
|
||||||
const resizeImage = (image, width, height, sx = null, sy = null) => {
|
const resizeImage = (image, width, height, sx = null, sy = null) => {
|
||||||
|
|
Reference in New Issue