Skip to content

Commit f7318c1

Browse files
susnuxbackportbot[bot]
authored andcommitted
fix(theming): remove node-vibrant dependency and usage (was moved to backend)
The color extraction is handled by the backend nowadays, this was not used by the backend anymore. Reduce depdencies + compiled size + security warning on that dependency. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent abab62b commit f7318c1

File tree

3 files changed

+31
-591
lines changed

3 files changed

+31
-591
lines changed

apps/theming/src/components/BackgroundSettings.vue

+4-45
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,12 @@
7878
</template>
7979

8080
<script>
81-
import { generateFilePath, generateRemoteUrl, generateUrl } from '@nextcloud/router'
82-
import { getCurrentUser } from '@nextcloud/auth'
81+
import { generateFilePath, generateUrl } from '@nextcloud/router'
8382
import { getFilePickerBuilder, showError } from '@nextcloud/dialogs'
8483
import { loadState } from '@nextcloud/initial-state'
85-
import { Palette } from 'node-vibrant/lib/color.js'
8684
import axios from '@nextcloud/axios'
8785
import debounce from 'debounce'
8886
import NcColorPicker from '@nextcloud/vue/dist/Components/NcColorPicker.js'
89-
import Vibrant from 'node-vibrant'
9087

9188
import Check from 'vue-material-design-icons/Check.vue'
9289
import ImageEdit from 'vue-material-design-icons/ImageEdit.vue'
@@ -217,9 +214,9 @@ export default {
217214
this.update(result.data)
218215
},
219216

220-
async setFile(path, color = null) {
217+
async setFile(path) {
221218
this.loading = 'custom'
222-
const result = await axios.post(generateUrl('/apps/theming/background/custom'), { value: path, color })
219+
const result = await axios.post(generateUrl('/apps/theming/background/custom'), { value: path })
223220
this.update(result.data)
224221
},
225222

@@ -264,45 +261,7 @@ export default {
264261
}
265262

266263
this.loading = 'custom'
267-
268-
// Extract primary color from image
269-
let response = null
270-
let color = null
271-
try {
272-
const fileUrl = generateRemoteUrl('dav/files/' + getCurrentUser().uid + path)
273-
response = await axios.get(fileUrl, { responseType: 'blob' })
274-
const blobUrl = URL.createObjectURL(response.data)
275-
const palette = await this.getColorPaletteFromBlob(blobUrl)
276-
277-
// DarkVibrant is accessible AND visually pleasing
278-
// Vibrant is not accessible enough and others are boring
279-
color = palette?.DarkVibrant?.hex
280-
this.setFile(path, color)
281-
282-
// Log data
283-
console.debug('Extracted colour', color, 'from custom image', path, palette)
284-
} catch (error) {
285-
this.setFile(path)
286-
console.error('Unable to extract colour from custom image', { error, path, response, color })
287-
}
288-
},
289-
290-
/**
291-
* Extract a Vibrant color palette from a blob URL
292-
*
293-
* @param {string} blobUrl the blob URL
294-
* @return {Promise<Palette>}
295-
*/
296-
getColorPaletteFromBlob(blobUrl) {
297-
return new Promise((resolve, reject) => {
298-
const vibrant = new Vibrant(blobUrl)
299-
vibrant.getPalette((error, palette) => {
300-
if (error) {
301-
reject(error)
302-
}
303-
resolve(palette)
304-
})
305-
})
264+
this.setFile(path)
306265
},
307266
},
308267
}

0 commit comments

Comments
 (0)