project_key.js 689 B

123456789101112131415161718192021222324
  1. // Keep in sync with services/web/app/src/Features/History/project_key.js
  2. const _ = require('lodash')
  3. const path = require('node:path')
  4. //
  5. // The advice in http://docs.aws.amazon.com/AmazonS3/latest/dev/
  6. // request-rate-perf-considerations.html is to avoid sequential key prefixes,
  7. // so we reverse the project ID part of the key as they suggest.
  8. //
  9. function format(projectId) {
  10. const prefix = naiveReverse(pad(projectId))
  11. return path.join(prefix.slice(0, 3), prefix.slice(3, 6), prefix.slice(6))
  12. }
  13. function pad(number) {
  14. return _.padStart(number, 9, '0')
  15. }
  16. function naiveReverse(string) {
  17. return string.split('').reverse().join('')
  18. }
  19. exports.format = format
  20. exports.pad = pad