...
This commit is contained in:
		@@ -54,23 +54,39 @@ const flash = ({ type, msg }) => {
 | 
				
			|||||||
      renderTags(res.tags);
 | 
					      renderTags(res.tags);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const get = async (url, data) => {
 | 
					    const queryapi = async (url, data, method = 'GET') => {
 | 
				
			||||||
      let s = [];
 | 
					      let req;
 | 
				
			||||||
      for(const [ key, val ] of Object.entries(data))
 | 
					      if(method == 'POST') {
 | 
				
			||||||
        s.push(encodeURIComponent(key) + "=" + encodeURIComponent(val));
 | 
					        req = await fetch(url, {
 | 
				
			||||||
      return (await fetch(url + "?" + s.join("&"))).json();
 | 
					          method: "POST",
 | 
				
			||||||
 | 
					          headers: {
 | 
				
			||||||
 | 
					            "Content-Type": "application/json"
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          body: JSON.stringify(data)
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else {
 | 
				
			||||||
 | 
					        let s = [];
 | 
				
			||||||
 | 
					        for(const [ key, val ] of Object.entries(data))
 | 
				
			||||||
 | 
					          s.push(encodeURIComponent(key) + "=" + encodeURIComponent(val));
 | 
				
			||||||
 | 
					        req = await fetch(url + '?' + s.join('&'));
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      return await req.json();
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const deletePost = async postid => await get("/api/v2/admin/deletepost", {
 | 
					    const get  = async (url, data) => queryapi(url, data, 'GET');
 | 
				
			||||||
 | 
					    const post = async (url, data) => queryapi(url, data, 'POST');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const deletePost = async postid => await post("/api/v2/admin/deletepost", {
 | 
				
			||||||
      postid: postid
 | 
					      postid: postid
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
    const addTag = async (postid, tag) => await get("/api/v2/admin/tags/add", {
 | 
					    const addTag = async (postid, tag) => await post("/api/v2/admin/tags/add", {
 | 
				
			||||||
      postid: postid,
 | 
					      postid: postid,
 | 
				
			||||||
      tag: tag
 | 
					      tag: tag
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
    const deleteTag = async (postid, tagid) => await get("/api/v2/admin/tags/delete", {
 | 
					    const deleteTag = async (postid, tagid) => await post("/api/v2/admin/tags/delete", {
 | 
				
			||||||
      postid: postid,
 | 
					      postid: postid,
 | 
				
			||||||
      tagid: tagid
 | 
					      tagid: tagid
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@@ -235,7 +251,7 @@ const flash = ({ type, msg }) => {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const toggleFavEvent = async e => {
 | 
					    const toggleFavEvent = async e => {
 | 
				
			||||||
      const res = await get('/api/v2/admin/togglefav', {
 | 
					      const res = await post('/api/v2/admin/togglefav', {
 | 
				
			||||||
        postid: postid
 | 
					        postid: postid
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      if(res.success) {
 | 
					      if(res.success) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -85,16 +85,16 @@ export default (router, tpl) => {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
    // adminzeugs
 | 
					    // adminzeugs
 | 
				
			||||||
    group.get(/\/admin\/tags\/add$/, auth, async (req, res) => {
 | 
					    group.post(/\/admin\/tags\/add$/, auth, async (req, res) => {
 | 
				
			||||||
      if(!req.url.qs.postid || !req.url.qs.tag) {
 | 
					      if(!req.post.postid || !req.post.tag) {
 | 
				
			||||||
        return res.reply({ body: JSON.stringify({
 | 
					        return res.reply({ body: JSON.stringify({
 | 
				
			||||||
          success: false,
 | 
					          success: false,
 | 
				
			||||||
          msg: "missing postid or tag"
 | 
					          msg: "missing postid or tag"
 | 
				
			||||||
        })});
 | 
					        })});
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
      const postid = +req.url.qs.postid;
 | 
					      const postid = +req.post.postid;
 | 
				
			||||||
      const tag = req.url.qs.tag?.trim();
 | 
					      const tag = req.post.tag?.trim();
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
      if(tag.length >= 45) {
 | 
					      if(tag.length >= 45) {
 | 
				
			||||||
        return res.reply({ body: JSON.stringify({
 | 
					        return res.reply({ body: JSON.stringify({
 | 
				
			||||||
@@ -136,16 +136,16 @@ export default (router, tpl) => {
 | 
				
			|||||||
      })});
 | 
					      })});
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
    group.get(/\/admin\/tags\/delete$/, auth, async (req, res) => {
 | 
					    group.post(/\/admin\/tags\/delete$/, auth, async (req, res) => {
 | 
				
			||||||
      if(!req.url.qs.postid || !req.url.qs.tagid) {
 | 
					      if(!req.post.postid || !req.post.tagid) {
 | 
				
			||||||
        return res.reply({ body: JSON.stringify({
 | 
					        return res.reply({ body: JSON.stringify({
 | 
				
			||||||
          success: false,
 | 
					          success: false,
 | 
				
			||||||
          msg: "missing postid or tag"
 | 
					          msg: "missing postid or tag"
 | 
				
			||||||
        })});
 | 
					        })});
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
      const postid = +req.url.qs.postid;
 | 
					      const postid = +req.post.postid;
 | 
				
			||||||
      const tagid = +req.url.qs.tagid;
 | 
					      const tagid = +req.post.tagid;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
      const tags = await lib.getTags(postid);
 | 
					      const tags = await lib.getTags(postid);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
@@ -206,14 +206,14 @@ export default (router, tpl) => {
 | 
				
			|||||||
      })});
 | 
					      })});
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
    group.get(/\/admin\/deletepost$/, auth, async (req, res) => {
 | 
					    group.post(/\/admin\/deletepost$/, auth, async (req, res) => {
 | 
				
			||||||
      if(!req.url.qs.postid) {
 | 
					      if(!req.post.postid) {
 | 
				
			||||||
        return res.reply({ body: JSON.stringify({
 | 
					        return res.reply({ body: JSON.stringify({
 | 
				
			||||||
          success: true,
 | 
					          success: true,
 | 
				
			||||||
          msg: "no postid"
 | 
					          msg: "no postid"
 | 
				
			||||||
        })});
 | 
					        })});
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      const postid = +req.url.qs.postid;
 | 
					      const postid = +req.post.postid;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
      await sql("items").where("id", postid).del();
 | 
					      await sql("items").where("id", postid).del();
 | 
				
			||||||
      res.reply({ body: JSON.stringify({
 | 
					      res.reply({ body: JSON.stringify({
 | 
				
			||||||
@@ -221,8 +221,8 @@ export default (router, tpl) => {
 | 
				
			|||||||
      })});
 | 
					      })});
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    group.get(/\/admin\/togglefav$/, auth, async (req, res) => {
 | 
					    group.post(/\/admin\/togglefav$/, auth, async (req, res) => {
 | 
				
			||||||
      const postid = +req.url.qs.postid;
 | 
					      const postid = +req.post.postid;
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      let favs = await sql('favorites').select('user_id').where('item_id', postid);
 | 
					      let favs = await sql('favorites').select('user_id').where('item_id', postid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user