use regex + static method to centralize hashedfavicon URL behavior

This commit is contained in:
Nick Krecklow
2020-05-08 16:00:36 -05:00
parent 15814cf86b
commit 04d94a9461
2 changed files with 28 additions and 23 deletions

View File

@ -1,13 +1,11 @@
const crypto = require('crypto')
const TimeTracker = require('./time')
const Server = require('./server')
const config = require('../config')
const minecraftVersions = require('../minecraft_versions')
const HASHED_FAVICON_URL = '/hashedfavicon_'
const HASHED_FAVICON_EXTENSION = '.png'
class ServerRegistration {
serverId
lastFavicon
@ -233,16 +231,18 @@ class ServerRegistration {
if (!this._faviconHasher) {
this._faviconHasher = crypto.createHash('md5')
}
this.faviconHash = this._faviconHasher.update(favicon).digest('hex').toString()
return true
}
return false
}
getFaviconUrl () {
if (this.faviconHash) {
return HASHED_FAVICON_URL + this.faviconHash + HASHED_FAVICON_EXTENSION
return Server.getHashedFaviconUrl(this.faviconHash)
} else if (this.data.favicon) {
return this.data.favicon
}