mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-11 16:56:34 -05:00
ee85d948e2
GitOrigin-RevId: ef2ef77e26df59d1af3df6dc664e284d3c70102d
23 lines
610 B
JavaScript
23 lines
610 B
JavaScript
const _ = require('lodash')
|
|
const path = require('path')
|
|
|
|
//
|
|
// The advice in http://docs.aws.amazon.com/AmazonS3/latest/dev/
|
|
// request-rate-perf-considerations.html is to avoid sequential key prefixes,
|
|
// so we reverse the project ID part of the key as they suggest.
|
|
//
|
|
function format(projectId) {
|
|
const prefix = naiveReverse(pad(projectId))
|
|
return path.join(prefix.slice(0, 3), prefix.slice(3, 6), prefix.slice(6))
|
|
}
|
|
|
|
function pad(number) {
|
|
return _.padStart(number, 9, '0')
|
|
}
|
|
|
|
function naiveReverse(string) {
|
|
return string.split('').reverse().join('')
|
|
}
|
|
|
|
exports.format = format
|
|
exports.pad = pad
|