Specify an explicit upload bucket ID with ?sid= param. (Closes #42)

This commit is contained in:
Christoph Wiechert
2018-12-14 16:02:03 +01:00
parent 3688ce6c2b
commit fa52624374
3 changed files with 31 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ It's an alternative to paid services like Dropbox, WeTransfer.
* Password protected download list ([AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard)) * Password protected download list ([AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard))
* `/admin` Page lists bucket information, [Screenshot](https://raw.githubusercontent.com/psi-4ward/psitransfer/master/docs/PsiTransfer-Admin.png) (_disabled until you set `adminPass` config value_) * `/admin` Page lists bucket information, [Screenshot](https://raw.githubusercontent.com/psi-4ward/psitransfer/master/docs/PsiTransfer-Admin.png) (_disabled until you set `adminPass` config value_)
* Lightweight [Vue](https://vuejs.org) based frontend apps. Gzipped (on by default) less than 65k * Lightweight [Vue](https://vuejs.org) based frontend apps. Gzipped (on by default) less than 65k
* Explicit named bucket IDs with query param `sid=<myBucketID>`
**See the blog posts about PsiTransfer: https://psi.cx/tags/PsiTransfer/ and checkout the **See the blog posts about PsiTransfer: https://psi.cx/tags/PsiTransfer/ and checkout the
[Documentation](https://github.com/psi-4ward/psitransfer/tree/master/docs)** [Documentation](https://github.com/psi-4ward/psitransfer/tree/master/docs)**

View File

@@ -7,46 +7,46 @@
label(for='retention') Retention label(for='retention') Retention
| |
select#retention.form-control(:value='retention', :disabled='disabled', select#retention.form-control(:value='retention', :disabled='disabled',
@input="$store.commit('upload/RETENTION', $event.target.value)") @input="$store.commit('upload/RETENTION', $event.target.value)")
option(v-for='(label, seconds, index) in config.retentions', option(v-for='(label, seconds, index) in config.retentions',
:value="seconds", :selected="seconds == retention") {{ label }} :value="seconds", :selected="seconds === retention") {{ label }}
div div
label(for='password') Password label(for='password') Password
.input-group .input-group
input#password.form-control(type='text', :value='password', input#password.form-control(type='text', :value='password',
@input="$store.commit('upload/PASSWORD', $event.target.value)", @input="$store.commit('upload/PASSWORD', $event.target.value)",
:disabled='disabled', placeholder='optional') :disabled='disabled', placeholder='optional')
span.input-group-addon(style='cursor: pointer', title='generate password', @click='generatePassword()') span.input-group-addon(style='cursor: pointer', title='generate password', @click='generatePassword()')
icon(name="key") icon(name="key")
</template> </template>
<script type="text/babel"> <script type="text/babel">
"use strict"; "use strict";
import {mapState} from 'vuex'; import { mapState } from 'vuex';
import 'vue-awesome/icons/key'; import 'vue-awesome/icons/key';
const passGen = { const passGen = {
_pattern : /[A-Z0-9_\-\+\!]/, _pattern: /[A-Z0-9_\-+!]/,
_getRandomByte: function() { _getRandomByte: function() {
const result = new Uint8Array(1); const result = new Uint8Array(1);
var fixedcrypto = window.msCrypto; let fixedcrypto = window.msCrypto;
if (!fixedcrypto) { if (!fixedcrypto) {
var fixedcrypto = window.crypto; fixedcrypto = window.crypto;
} }
fixedcrypto.getRandomValues(result); fixedcrypto.getRandomValues(result);
return result[0]; return result[0];
}, },
generate: function(length) { generate: function(length) {
var fixedcrypto2 = window.msCrypto; let fixedcrypto2 = window.msCrypto;
if (!fixedcrypto2) { if (!fixedcrypto2) {
var fixedcrypto2 = window.crypto; fixedcrypto2 = window.crypto;
} }
if(!fixedcrypto2 || !fixedcrypto2.getRandomValues) return ''; if (!fixedcrypto2 || !fixedcrypto2.getRandomValues) return '';
return Array.apply(null, {'length': length}).map(function() { return Array.apply(null, { 'length': length }).map(function() {
let result; let result;
while(true) { while (true) {
result = String.fromCharCode(this._getRandomByte()); result = String.fromCharCode(this._getRandomByte());
if(this._pattern.test(result)) return result; if (this._pattern.test(result)) return result;
} }
}, this).join(''); }, this).join('');
} }
@@ -64,7 +64,7 @@
methods: { methods: {
generatePassword() { generatePassword() {
if(this.disabled) return; if (this.disabled) return;
this.$store.commit('upload/PASSWORD', passGen.generate(10)); this.$store.commit('upload/PASSWORD', passGen.generate(10));
} }
} }

View File

@@ -16,6 +16,16 @@ function humanFileSize(fileSizeInBytes) {
let onOnlineHandler = null; let onOnlineHandler = null;
let onOnlineHandlerAttached = false; let onOnlineHandlerAttached = false;
function getSid() {
// support setting an explicit SID by location search param
const match = document.location.search.match(/sid=([^&]+)/);
if(match) {
return match[1];
} else {
return md5(uuid()).toString().substr(0, 12);
}
}
export default { export default {
namespaced: true, namespaced: true,
@@ -23,7 +33,7 @@ export default {
retention: null, retention: null,
password: '', password: '',
files: [], files: [],
sid: md5(uuid()).toString().substr(0, 12), sid: getSid(),
bytesUploaded: 0, bytesUploaded: 0,
}, },