feature for ex-/including saved posts when exporting preferences

This commit is contained in:
teddit 2021-02-13 13:29:47 +01:00
parent aae8495b13
commit aeeeaa76b7
2 changed files with 15 additions and 1 deletions

View File

@ -55,7 +55,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
}
if(!subbed_subreddits_is_set)
res.clearCookie('subbed_subreddits')
return res.redirect('/preferences')
return res.redirect('/')
} catch(e) {
console.error(`Error setting imported preferences to the cookies. Key: ${key}.`, error)
}
@ -1456,6 +1456,14 @@ module.exports = (app, redis, fetch, RedditAPI) => {
})
app.post('/export_prefs', (req, res, next) => {
let export_saved = req.body.export_saved
let export_data = req.cookies
if(export_saved !== 'on') {
if(req.cookies.saved)
delete export_data.saved
}
let r = `${(Math.random().toString(36)+'00000000000000000').slice(2, 10+2).toUpperCase()}`
let key = `prefs_key:${r}`
redis.set(key, JSON.stringify(req.cookies), (error) => {

View File

@ -75,6 +75,9 @@ html
.setting
small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently.
br
label(for="export_saved") Export saved posts:
input(type="checkbox", name="export_saved", id="export_saved")
br
input(type="submit", value="Export preferences")
if preferences_key
- var protocol = 'http'
@ -89,5 +92,8 @@ html
.setting
small By exporting your preferences you can transfer your subscribed subreddits and preferences to another device. Or you could create a bookmark if you tend to delete your cookies frequently.
br
label(for="export_saved") Export saved posts:
input(type="checkbox", name="export_saved", id="export_saved")
br
input(type="submit", value="Export preferences")
include includes/footer.pug