selfhostable, read-only reddit client

fix search with args

Changed files
+3 -29
src
+1 -6
src/geddit.js
··· 241 241 options.q = query; 242 242 options.type = "link"; 243 243 244 - const params = { 245 - limit: 25, 246 - include_over_18: true, 247 - }; 248 - 249 244 return await fetch( 250 - `${this.host}/search.json?${new URLSearchParams(Object.assign(params, options))}`, 245 + `${this.host}/search.json?${new URLSearchParams(options)}`, 251 246 ) 252 247 .then((res) => res.json()) 253 248 .then((json) => json.data)
+2 -23
src/routes/index.js
··· 117 117 if (!req.query || !req.query.q) { 118 118 res.render("sub-search", { user: req.user }); 119 119 } else { 120 - const { q, options } = parseQuery(req.query.q); 121 - const { items, after } = await G.searchSubreddits(q, { 122 - include_over_18: (options.nsfw ?? "no") === "yes", 123 - }); 120 + const { items, after } = await G.searchSubreddits(q); 124 121 const subs = db 125 122 .query("SELECT subreddit FROM subscriptions WHERE user_id = $id") 126 123 .all({ id: req.user.id }) ··· 145 142 if (!req.query || !req.query.q) { 146 143 res.render("post-search", { user: req.user }); 147 144 } else { 148 - const { q, options } = parseQuery(req.query.q); 149 - const { items, after } = await G.searchSubmissions(q, { 150 - include_over_18: (options.nsfw ?? "no") === "yes", 151 - }); 145 + const { items, after } = await G.searchSubmissions(req.query.q); 152 146 const message = 153 147 items.length === 0 154 148 ? "no results found" ··· 163 157 }); 164 158 } 165 159 }); 166 - 167 - function parseQuery(q) { 168 - return q.split(/\s+/).reduce( 169 - (acc, word) => { 170 - if (word.includes(":")) { 171 - const [key, val] = word.split(":"); 172 - acc.options[key] = val; 173 - } else { 174 - acc.q += `${word} `; 175 - } 176 - return acc; 177 - }, 178 - { options: [], q: "" }, 179 - ); 180 - } 181 160 182 161 // GET /dashboard 183 162 router.get("/dashboard", authenticateToken, async (req, res) => {