This repository has been archived on 2026-07-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
drive/frontend/node_modules/tus-js-client/lib.esm/browser/fileSignature.js
Elijah 724d70e58b
Some checks failed
Automated Container Build / build-and-push (push) Failing after 12s
Inital build
2026-05-22 12:29:43 -07:00

34 lines
No EOL
1.1 KiB
JavaScript

import isReactNative from './isReactNative.js';
// TODO: Differenciate between input types
/**
* Generate a fingerprint for a file which will be used the store the endpoint
*
* @param {File} file
* @param {Object} options
* @param {Function} callback
*/
export default function fingerprint(file, options) {
if (isReactNative()) {
return Promise.resolve(reactNativeFingerprint(file, options));
}
return Promise.resolve(['tus-br', file.name, file.type, file.size, file.lastModified, options.endpoint].join('-'));
}
function reactNativeFingerprint(file, options) {
var exifHash = file.exif ? hashCode(JSON.stringify(file.exif)) : 'noexif';
return ['tus-rn', file.name || 'noname', file.size || 'nosize', exifHash, options.endpoint].join('/');
}
function hashCode(str) {
// from https://stackoverflow.com/a/8831937/151666
var hash = 0;
if (str.length === 0) {
return hash;
}
for (var i = 0; i < str.length; i++) {
var _char = str.charCodeAt(i);
hash = (hash << 5) - hash + _char;
hash &= hash; // Convert to 32bit integer
}
return hash;
}