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

Commit

Permalink
Fix #5251, add endpoint to check for indefinite shots (#5273)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb authored and jaredhirsch committed Jan 3, 2019
1 parent a1ac977 commit c6c7490
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,14 @@ app.get("/api/fxa-oauth/confirm-login", async function(req, res, next) {
}
});

app.get("/api/has-shots", async function(req, res) {
if (!(req.deviceId || req.accountId)) {
res.status(401).send("Authentication required");
}
const hasShots = await Shot.userHasShots(req.deviceId, req.accountId);
res.send(hasShots);
});

app.post("/watchdog/:submissionId", function(req, res) {
Watchdog.handleResult(req);
res.end();
Expand Down
33 changes: 33 additions & 0 deletions server/src/servershot.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,39 @@ Shot.deleteEverythingForDevice = function(backend, deviceId, accountId) {
.then(deleteShotRecords);
};

Shot.userHasShots = async function(deviceId, accountId) {
let deviceIds = [{id: deviceId}];
if (accountId) {
deviceIds = await db.select(
`SELECT devices.id
FROM devices
WHERE devices.id = $1 OR devices.accountid = $2
`,
[deviceId, accountId]);
}
deviceIds = deviceIds.map(row => row.id);
const markers1 = db.markersForArgs(1, deviceIds.length);
const markers2 = db.markersForArgs(deviceIds.length + 1, deviceIds.length);
const hasSome = await db.select(`
SELECT
EXISTS (
SELECT data.id
FROM data
WHERE data.expire_time IS NULL
AND NOT data.deleted
AND data.deviceid IN (${markers1})
) AS hasindefinite,
EXISTS (
SELECT data.id
FROM data
WHERE NOT data.deleted
AND data.deviceid IN (${markers2})
) AS hasany
`, deviceIds.concat(deviceIds));
return {hasIndefinite: hasSome[0].hasindefinite, hasAny: hasSome[0].hasany};
};


const ClipRewrites = class ClipRewrites {

constructor(shot) {
Expand Down

0 comments on commit c6c7490

Please sign in to comment.