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

Fix #5251, add endpoint to check for indefinite shots #5273

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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