Last active
July 21, 2021 16:24
-
-
Save phette23/9279de4260ff681cbdfc12e10275e2d3 to your computer and use it in GitHub Desktop.
find hash in openEQUELLA file storage path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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