mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 06:08:46 -04:00
refactor: remove global md5 and replace other use cases with common depenency
1. By replacing `blueimp-md5` with `crypto-browserify` we reduce the dependencies because the latter one is already used by `@nextcloud/upload`. 2. Drop the global `md5` as the changed implementation would need a wrapper, but its also not used anymore and deprecated since Nextcloud 20. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
c8eeade151
commit
b613bb26bd
4 changed files with 33 additions and 39 deletions
|
|
@ -18,7 +18,6 @@ import Backbone from 'backbone'
|
|||
import ClipboardJS from 'clipboard'
|
||||
import { dav } from 'davclient.js'
|
||||
import Handlebars from 'handlebars'
|
||||
import md5 from 'blueimp-md5'
|
||||
import moment from 'moment'
|
||||
import 'select2'
|
||||
import 'select2/select2.css'
|
||||
|
|
@ -81,8 +80,6 @@ setDeprecatedProp('Backbone', () => Backbone, 'please ship your own, this will b
|
|||
setDeprecatedProp(['Clipboard', 'ClipboardJS'], () => ClipboardJS, 'please ship your own, this will be removed in Nextcloud 20')
|
||||
window.dav = dav
|
||||
setDeprecatedProp('Handlebars', () => Handlebars, 'please ship your own, this will be removed in Nextcloud 20')
|
||||
// Global md5 only required for: apps/files/js/file-upload.js
|
||||
setDeprecatedProp('md5', () => md5, 'please ship your own, this will be removed in Nextcloud 20')
|
||||
setDeprecatedProp('moment', () => moment, 'please ship your own, this will be removed in Nextcloud 20')
|
||||
|
||||
window.OC = OC
|
||||
|
|
|
|||
59
core/src/jquery/placeholder.js
vendored
59
core/src/jquery/placeholder.js
vendored
|
|
@ -1,12 +1,13 @@
|
|||
/* eslint-disable jsdoc/require-jsdoc */
|
||||
/* eslint-disable no-extend-native */
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2013-2016 ownCloud, Inc.
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
import { createHash } from 'crypto-browserify'
|
||||
import $ from 'jquery'
|
||||
import md5 from 'blueimp-md5'
|
||||
|
||||
/*
|
||||
* Adds a background color to the element called on and adds the first character
|
||||
|
|
@ -42,17 +43,19 @@ import md5 from 'blueimp-md5'
|
|||
*
|
||||
* Will return the rgb parameters within the following object:
|
||||
*
|
||||
* Color {r: 208, g: 158, b: 109}
|
||||
* Color {r: 208, g: 158, b: 109}
|
||||
*
|
||||
*/
|
||||
|
||||
const toRgb = (s) => {
|
||||
// Normalize hash
|
||||
var hash = s.toLowerCase()
|
||||
let hash = s.toLowerCase()
|
||||
|
||||
// Already a md5 hash?
|
||||
if (hash.match(/^([0-9a-f]{4}-?){8}$/) === null) {
|
||||
hash = md5(hash)
|
||||
createHash('md5')
|
||||
.update(hash)
|
||||
.digest('hex')
|
||||
}
|
||||
|
||||
hash = hash.replace(/[^0-9a-f]/g, '')
|
||||
|
|
@ -64,7 +67,7 @@ const toRgb = (s) => {
|
|||
}
|
||||
|
||||
function stepCalc(steps, ends) {
|
||||
var step = new Array(3)
|
||||
const step = new Array(3)
|
||||
step[0] = (ends[1].r - ends[0].r) / steps
|
||||
step[1] = (ends[1].g - ends[0].g) / steps
|
||||
step[2] = (ends[1].b - ends[0].b) / steps
|
||||
|
|
@ -72,43 +75,43 @@ const toRgb = (s) => {
|
|||
}
|
||||
|
||||
function mixPalette(steps, color1, color2) {
|
||||
var palette = []
|
||||
const palette = []
|
||||
palette.push(color1)
|
||||
var step = stepCalc(steps, [color1, color2])
|
||||
for (var i = 1; i < steps; i++) {
|
||||
var r = parseInt(color1.r + (step[0] * i))
|
||||
var g = parseInt(color1.g + (step[1] * i))
|
||||
var b = parseInt(color1.b + (step[2] * i))
|
||||
const step = stepCalc(steps, [color1, color2])
|
||||
for (let i = 1; i < steps; i++) {
|
||||
const r = parseInt(color1.r + (step[0] * i))
|
||||
const g = parseInt(color1.g + (step[1] * i))
|
||||
const b = parseInt(color1.b + (step[2] * i))
|
||||
palette.push(new Color(r, g, b))
|
||||
}
|
||||
return palette
|
||||
}
|
||||
|
||||
const red = new Color(182, 70, 157);
|
||||
const yellow = new Color(221, 203, 85);
|
||||
const blue = new Color(0, 130, 201); // Nextcloud blue
|
||||
const red = new Color(182, 70, 157)
|
||||
const yellow = new Color(221, 203, 85)
|
||||
const blue = new Color(0, 130, 201) // Nextcloud blue
|
||||
// Number of steps to go from a color to another
|
||||
// 3 colors * 6 will result in 18 generated colors
|
||||
const steps = 6;
|
||||
const steps = 6
|
||||
|
||||
const palette1 = mixPalette(steps, red, yellow);
|
||||
const palette2 = mixPalette(steps, yellow, blue);
|
||||
const palette3 = mixPalette(steps, blue, red);
|
||||
const palette1 = mixPalette(steps, red, yellow)
|
||||
const palette2 = mixPalette(steps, yellow, blue)
|
||||
const palette3 = mixPalette(steps, blue, red)
|
||||
|
||||
const finalPalette = palette1.concat(palette2).concat(palette3);
|
||||
const finalPalette = palette1.concat(palette2).concat(palette3)
|
||||
|
||||
// Convert a string to an integer evenly
|
||||
function hashToInt(hash, maximum) {
|
||||
var finalInt = 0
|
||||
var result = []
|
||||
let finalInt = 0
|
||||
const result = []
|
||||
|
||||
// Splitting evenly the string
|
||||
for (var i = 0; i < hash.length; i++) {
|
||||
for (let i = 0; i < hash.length; i++) {
|
||||
// chars in md5 goes up to f, hex:16
|
||||
result.push(parseInt(hash.charAt(i), 16) % 16)
|
||||
}
|
||||
// Adds up all results
|
||||
for (var j in result) {
|
||||
for (const j in result) {
|
||||
finalInt += result[j]
|
||||
}
|
||||
// chars in md5 goes up to f, hex:16
|
||||
|
|
@ -129,11 +132,11 @@ $.fn.imageplaceholder = function(seed, text, size) {
|
|||
text = text || seed
|
||||
|
||||
// Compute the hash
|
||||
var rgb = toRgb(seed)
|
||||
const rgb = toRgb(seed)
|
||||
this.css('background-color', 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')')
|
||||
|
||||
// Placeholders are square
|
||||
var height = this.height() || size || 32
|
||||
const height = this.height() || size || 32
|
||||
this.height(height)
|
||||
this.width(height)
|
||||
|
||||
|
|
@ -147,8 +150,8 @@ $.fn.imageplaceholder = function(seed, text, size) {
|
|||
this.css('font-size', (height * 0.55) + 'px')
|
||||
|
||||
if (seed !== null && seed.length) {
|
||||
var placeholderText = text.replace(/\s+/g, ' ').trim().split(' ', 2).map((word) => word[0].toUpperCase()).join('')
|
||||
this.html(placeholderText);
|
||||
const placeholderText = text.replace(/\s+/g, ' ').trim().split(' ', 2).map((word) => word[0].toUpperCase()).join('')
|
||||
this.html(placeholderText)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
8
package-lock.json
generated
8
package-lock.json
generated
|
|
@ -37,7 +37,6 @@
|
|||
"@vueuse/core": "^11.3.0",
|
||||
"@vueuse/integrations": "^11.3.0",
|
||||
"backbone": "^1.6.1",
|
||||
"blueimp-md5": "^2.19.0",
|
||||
"blurhash": "^2.0.5",
|
||||
"browserslist-useragent-regexp": "^4.1.3",
|
||||
"camelcase": "^8.0.0",
|
||||
|
|
@ -45,6 +44,7 @@
|
|||
"clipboard": "^2.0.11",
|
||||
"color": "^5.0.0",
|
||||
"core-js": "^3.45.0",
|
||||
"crypto-browserify": "^3.12.1",
|
||||
"davclient.js": "nextcloud-deps/davclient.js#59d7777d7fe290c5f1fd74a58e7eb529b63e153d",
|
||||
"debounce": "^2.2.0",
|
||||
"dompurify": "^3.2.6",
|
||||
|
|
@ -8725,12 +8725,6 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/blueimp-md5": {
|
||||
"version": "2.19.0",
|
||||
"resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.19.0.tgz",
|
||||
"integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/blurhash": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/blurhash/-/blurhash-2.0.5.tgz",
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@
|
|||
"@vueuse/core": "^11.3.0",
|
||||
"@vueuse/integrations": "^11.3.0",
|
||||
"backbone": "^1.6.1",
|
||||
"blueimp-md5": "^2.19.0",
|
||||
"blurhash": "^2.0.5",
|
||||
"browserslist-useragent-regexp": "^4.1.3",
|
||||
"camelcase": "^8.0.0",
|
||||
|
|
@ -76,6 +75,7 @@
|
|||
"clipboard": "^2.0.11",
|
||||
"color": "^5.0.0",
|
||||
"core-js": "^3.45.0",
|
||||
"crypto-browserify": "^3.12.1",
|
||||
"davclient.js": "nextcloud-deps/davclient.js#59d7777d7fe290c5f1fd74a58e7eb529b63e153d",
|
||||
"debounce": "^2.2.0",
|
||||
"dompurify": "^3.2.6",
|
||||
|
|
|
|||
Loading…
Reference in a new issue