mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-03-02 10:41:36 +00:00
Allow data syncing and deletion
This commit is contained in:
parent
e0bc0d2e81
commit
2faaa2e18b
10 changed files with 138 additions and 28 deletions
|
|
@ -1,7 +1,7 @@
|
|||
const {redirect} = require("pinski/plugins")
|
||||
const db = require("../utils/db")
|
||||
const constants = require("../utils/constants")
|
||||
const {getUser} = require("../utils/getuser")
|
||||
const {getUser, setToken} = require("../utils/getuser")
|
||||
const validate = require("../utils/validate")
|
||||
const V = validate.V
|
||||
const {fetchChannel} = require("../utils/youtube")
|
||||
|
|
@ -54,5 +54,45 @@ module.exports = [
|
|||
})
|
||||
.go()
|
||||
}
|
||||
},
|
||||
{
|
||||
route: `/formapi/erase`, methods: ["POST"], upload: true, code: async ({req, fill, body}) => {
|
||||
return new V()
|
||||
.with(validate.presetLoad({body}))
|
||||
.with(validate.presetURLParamsBody())
|
||||
.with(validate.presetEnsureParams(["token"]))
|
||||
.last(async state => {
|
||||
const {params} = state
|
||||
const token = params.get("token")
|
||||
;["Subscriptions", "Settings", "SeenTokens", "WatchedVideos"].forEach(table => {
|
||||
db.prepare(`DELETE FROM ${table} WHERE token = ?`).run(token)
|
||||
})
|
||||
return {
|
||||
statusCode: 303,
|
||||
headers: {
|
||||
location: "/",
|
||||
"set-cookie": `token=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax`
|
||||
},
|
||||
content: {
|
||||
status: "ok"
|
||||
}
|
||||
}
|
||||
})
|
||||
.go()
|
||||
}
|
||||
},
|
||||
{
|
||||
route: "/formapi/importsession/(\\w+)", methods: ["GET"], code: async ({req, fill}) => {
|
||||
return {
|
||||
statusCode: 303,
|
||||
headers: setToken({
|
||||
location: "/subscriptions"
|
||||
}, fill[0]),
|
||||
contentType: "application/json",
|
||||
content: {
|
||||
status: "ok"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ module.exports = [
|
|||
route: "/settings", methods: ["GET"], code: async ({req}) => {
|
||||
const user = getUser(req)
|
||||
const settings = user.getSettings()
|
||||
return render(200, "pug/settings.pug", {constants, settings})
|
||||
return render(200, "pug/settings.pug", {constants, user, settings})
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ module.exports = [
|
|||
videos = db.prepare(`SELECT * FROM Videos WHERE authorId IN (${template}) ORDER BY published DESC LIMIT 60`).all(subscriptions)
|
||||
.map(video => {
|
||||
video.publishedText = timeToPastText(video.published * 1000)
|
||||
console.log(watchedVideos, video.videoId)
|
||||
video.watched = watchedVideos.includes(video.videoId)
|
||||
return video
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue