diff options
author | Martin Herkt <lachs0r@srsfckn.biz> | 2017-10-27 08:52:45 +0200 |
---|---|---|
committer | Martin Herkt <lachs0r@srsfckn.biz> | 2017-10-27 08:53:19 +0200 |
commit | c3c29ab500b9ccf3a0cd1031df026337e4c2b1f9 (patch) | |
tree | b79fb585b67e255cb97c5dac38709475df287931 | |
parent | Add NSFW filter to address query commands (diff) | |
download | hex-zero-c3c29ab500b9ccf3a0cd1031df026337e4c2b1f9.tar.gz hex-zero-c3c29ab500b9ccf3a0cd1031df026337e4c2b1f9.tar.bz2 hex-zero-c3c29ab500b9ccf3a0cd1031df026337e4c2b1f9.zip |
Faster query commands, add removed query filter
-rwxr-xr-x | fhost.py | 43 |
1 files changed, 31 insertions, 12 deletions
@@ -109,6 +109,14 @@ class File(db.Model): else: return url_for("get", path=n, _external=True) + "\n" + def pprint(self): + print("url: {}".format(self.getname())) + vals = vars(self) + + for v in vals: + if not v.startswith("_sa"): + print("{}: {}".format(v, vals[v])) + def getpath(fn): return os.path.join(app.config["FHOST_STORAGE_PATH"], fn) @@ -445,28 +453,27 @@ def query(name): f = File.query.get(id) if f: - print("url: {}".format(f.getname())) - vals = vars(f) - - for v in vals: - if not v.startswith("_sa"): - print("{}: {}".format(v, vals[v])) + f.pprint() @manager.command def queryhash(h): f = File.query.filter_by(sha256=h).first() + if f: - query(su.enbase(f.id, 1)) + f.pprint() @manager.command -def queryaddr(a, nsfw=False): +def queryaddr(a, nsfw=False, removed=False): res = File.query.filter_by(addr=a) + if not removed: + res = res.filter(File.removed != True) + if nsfw: res = res.filter(File.nsfw_score > app.config["NSFW_THRESHOLD"]) for f in res: - query(su.enbase(f.id, 1)) + f.pprint() def nsfw_detect(f): try: @@ -500,15 +507,27 @@ def update_nsfw(): @manager.command -def querybl(nsfw=False): +def querybl(nsfw=False, removed=False): + blist = [] if os.path.isfile(app.config["FHOST_UPLOAD_BLACKLIST"]): with open(app.config["FHOST_UPLOAD_BLACKLIST"], "r") as bl: for l in bl.readlines(): if not l.startswith("#"): if not ":" in l: - queryaddr("::ffff:" + l.rstrip(), nsfw) + blist.append("::ffff:" + l.rstrip()) else: - queryaddr(l.strip(), nsfw) + blist.append(l.strip()) + + res = File.query.filter(File.addr.in_(blist)) + + if not removed: + res = res.filter(File.removed != True) + + if nsfw: + res = res.filter(File.nsfw_score > app.config["NSFW_THRESHOLD"]) + + for f in res: + f.pprint() if __name__ == "__main__": manager.run() |