Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
delete image files on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Apr 11, 2017
1 parent ebe57df commit 8271b63
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions server/src/servershot.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,24 +540,45 @@ Shot.setExpiration = function (backend, shotId, deviceId, expiration) {
};

Shot.deleteShot = function (backend, shotId, deviceId) {
return db.update(
`DELETE FROM data
WHERE id = $1
AND deviceid = $2
`,
[shotId, deviceId]
);
return Shot.get(backend, shotId, deviceId)
.then((shot) => {
const clipRewrites = new ClipRewrites(shot);
clipRewrites.clear();
return db.transaction((client) => {
return clipRewrites.commit(client);
});
})
.then(() => {
return db.update(
`DELETE FROM data
WHERE id = $1
AND deviceid = $2
`,
[shotId, deviceId]
);
});
};

Shot.deleteEverythingForDevice = function (backend, deviceId) {
return db.select(
`SELECT DISTINCT devices.id
FROM devices, devices AS devices2
WHERE devices.id = $1
OR (devices.accountid = devices2.accountid
AND devices2.id = $1)
`,
`SELECT images.id
FROM images JOIN data
ON images.shotid = data.id
WHERE data.deviceid = $1`,
[deviceId]
).then((rows) => {
rows.forEach((row) => del(row.id))
}
).then(() => {
return db.select(
`SELECT DISTINCT devices.id
FROM devices, devices AS devices2
WHERE devices.id = $1
OR (devices.accountid = devices2.accountid
AND devices2.id = $1)
`,
[deviceId]);
}
).then((rows) => {
let ids = [];
for (let i=0; i<rows.length; i++) {
Expand Down Expand Up @@ -636,6 +657,13 @@ ClipRewrites = class ClipRewrites {
this.shot.fullScreenThumbnail = this.oldFullScreenThumbnail;
}

clear() {
this.unedited = [];
this.toInsert = {};
this.toInsertClipIds = [];
this.toInsertThumbnail = null;
}

commands() {
let commands = [];
if (this.toInsertThumbnail !== null) {
Expand Down

0 comments on commit 8271b63

Please sign in to comment.