Skip to content

Instantly share code, notes, and snippets.

@phette23
Last active July 21, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/9279de4260ff681cbdfc12e10275e2d3 to your computer and use it in GitHub Desktop.
Save phette23/9279de4260ff681cbdfc12e10275e2d3 to your computer and use it in GitHub Desktop.
find hash in openEQUELLA file storage path
#!/usr/bin/env node
//jshint node:true
// useful for finding location of files on server, for non-advanced storage config location is
// {{data dir}}/Institutions/{{institution name}}/Attachments/${hashCode(uuid)}/${uuid}/${version}
// for advanced storage config it's
// {{data dir}}/Institutions/{{institution name}}/Attachments/${collection UUID}/${hashCode(uuid)}/${uuid}/${version}
const readline = require('readline')
let hashCode = function(str){
let hash = 0
if (str.length == 0) return hash
for (let i = 0; i < str.length; i++) {
let char = str.charCodeAt(i)
hash = ((hash<<5)-hash)+char
hash = hash & hash // Convert to 32bit integer
}
return hash & 127
}
if (require && require.main == module) {
// CLI arguments, no piped data
if (process.stdin.isTTY) {
let uuid = process.argv[2]
if (uuid) console.log(hashCode(uuid)) && process.exit(0)
} else {
// data is being piped through stdin
const rl = readline.createInterface({ input: process.stdin })
rl.on('line', uuid => console.log(hashCode(uuid)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment