Skip to content

Commit

Permalink
feat: allow STRU to take name suggesstion
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Mar 10, 2017
1 parent 9276f7f commit b7e17af
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/commands/registration/stou.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ module.exports = {
directive: 'STOU',
handler: function (args) {
if (!this.fs) return this.reply(550, 'File system not instantiated');
if (!this.fs.getUniqueName) return this.reply(402, 'Not supported by file system');
if (!this.fs.get || !this.fs.getUniqueName) return this.reply(402, 'Not supported by file system');

args.command._[1] = this.fs.getUniqueName();
return stor.call(this, args);
const fileName = args.command._[1];
return this.fs.get(fileName)
.catch(() => fileName) // does not exist, name is unique
.then(() => this.fs.getUniqueName()) // exists, must create new unique name
.then(name => {
args.command._[1] = name;
return stor.call(this, args);
});
},
syntax: '{{cmd}}',
description: 'Store file uniquely'
Expand Down

0 comments on commit b7e17af

Please sign in to comment.