From 86cb3213840403053aa9336dfdc5c947807c73d9 Mon Sep 17 00:00:00 2001 From: Ryan Mehri Date: Sun, 10 May 2020 18:09:49 -0600 Subject: Add auth check to get --- backend/cache/cache.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'backend/cache') diff --git a/backend/cache/cache.go b/backend/cache/cache.go index bac7ea8..1a8a7a1 100644 --- a/backend/cache/cache.go +++ b/backend/cache/cache.go @@ -1,6 +1,7 @@ package cache import ( + "errors" "sync" "github.com/jackyzha0/ctrl-v/db" @@ -13,6 +14,9 @@ type Cache struct { var C *Cache +var PasteNotFound = errors.New("could not find a paste with that hash") +var UserUnauthorized = errors.New("paste is password protected") + func init() { C = &Cache{ m: map[string]db.Paste{}, @@ -32,6 +36,15 @@ func (c *Cache) Get(hash string) (db.Paste, error) { // if it doesnt, lookup from db p, err := db.Lookup(hash) + if err != nil { + return p, PasteNotFound + } + + // if there is a password + if p.Password != "" { + return db.Paste{}, UserUnauthorized + } + c.add(p) return p, err } -- cgit v1.2.3