sparkles: Included avatar in export'
This commit is contained in:
parent
d4c9fdcbd7
commit
097af0fde6
2 changed files with 35 additions and 11 deletions
|
@ -337,17 +337,20 @@ UserController.prototype.export = (req, res) => {
|
|||
if(user === null) return res.sendStatus(400);
|
||||
let dir = createTempDir();
|
||||
if(!dir) return res.sendStatus(500);
|
||||
let zip = new Zip();
|
||||
zip.file("account.json", JSON.stringify(user.export(), null, 2));
|
||||
zip.generateAsync({
|
||||
type: "uint8array",
|
||||
comment: "freesewing.org",
|
||||
streamFiles: true
|
||||
}).then(function(data) {
|
||||
let file = path.join(dir, "export.zip");
|
||||
fs.writeFile(file, data, (err) => {
|
||||
log.info('dataExport', { user, req });
|
||||
return res.send({export: uri(file)});
|
||||
let avatar = fs.readFile(path.join(user.storagePath(), user.picture), (err, data) => {
|
||||
let zip = new Zip();
|
||||
zip.file("account.json", JSON.stringify(user.export(), null, 2));
|
||||
zip.file(user.picture, data);
|
||||
zip.generateAsync({
|
||||
type: "uint8array",
|
||||
comment: "freesewing.org",
|
||||
streamFiles: true
|
||||
}).then(function(data) {
|
||||
let file = path.join(dir, "export.zip");
|
||||
fs.writeFile(file, data, (err) => {
|
||||
log.info('dataExport', { user, req });
|
||||
return res.send({export: uri(file)});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ import bcrypt from 'mongoose-bcrypt';
|
|||
import { email, log } from "../utils";
|
||||
import encrypt from 'mongoose-encryption';
|
||||
import config from "../config";
|
||||
import path from "path";
|
||||
|
||||
const UserSchema = new Schema({
|
||||
email: {
|
||||
|
@ -160,4 +161,24 @@ UserSchema.methods.updateLoginTime = function(callback) {
|
|||
});
|
||||
}
|
||||
|
||||
UserSchema.methods.storagePath = function() {
|
||||
return path.join(
|
||||
config.storage,
|
||||
this.handle.substring(0,1),
|
||||
this.handle
|
||||
);
|
||||
}
|
||||
|
||||
UserSchema.methods.avatarUri = function(size = "l") {
|
||||
let prefix = (size === "l") ? "" : size+"-";
|
||||
return config.static
|
||||
+"/"
|
||||
+this.handle.substring(0,1)
|
||||
+"/"
|
||||
+this.handle
|
||||
+"/"
|
||||
+prefix
|
||||
+this.picture;
|
||||
}
|
||||
|
||||
export default mongoose.model('User', UserSchema);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue