1
0
Fork 0
forked from mia/0x0

Faster query commands, add removed query filter

This commit is contained in:
Martin Herkt 2017-10-27 08:52:45 +02:00
parent ebfbc6b153
commit c3c29ab500
No known key found for this signature in database
GPG key ID: C24B9CD04DC6AE7F

View file

@ -109,6 +109,14 @@ class File(db.Model):
else: else:
return url_for("get", path=n, _external=True) + "\n" 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): def getpath(fn):
return os.path.join(app.config["FHOST_STORAGE_PATH"], fn) return os.path.join(app.config["FHOST_STORAGE_PATH"], fn)
@ -445,28 +453,27 @@ def query(name):
f = File.query.get(id) f = File.query.get(id)
if f: if f:
print("url: {}".format(f.getname())) f.pprint()
vals = vars(f)
for v in vals:
if not v.startswith("_sa"):
print("{}: {}".format(v, vals[v]))
@manager.command @manager.command
def queryhash(h): def queryhash(h):
f = File.query.filter_by(sha256=h).first() f = File.query.filter_by(sha256=h).first()
if f: if f:
query(su.enbase(f.id, 1)) f.pprint()
@manager.command @manager.command
def queryaddr(a, nsfw=False): def queryaddr(a, nsfw=False, removed=False):
res = File.query.filter_by(addr=a) res = File.query.filter_by(addr=a)
if not removed:
res = res.filter(File.removed != True)
if nsfw: if nsfw:
res = res.filter(File.nsfw_score > app.config["NSFW_THRESHOLD"]) res = res.filter(File.nsfw_score > app.config["NSFW_THRESHOLD"])
for f in res: for f in res:
query(su.enbase(f.id, 1)) f.pprint()
def nsfw_detect(f): def nsfw_detect(f):
try: try:
@ -500,15 +507,27 @@ def update_nsfw():
@manager.command @manager.command
def querybl(nsfw=False): def querybl(nsfw=False, removed=False):
blist = []
if os.path.isfile(app.config["FHOST_UPLOAD_BLACKLIST"]): if os.path.isfile(app.config["FHOST_UPLOAD_BLACKLIST"]):
with open(app.config["FHOST_UPLOAD_BLACKLIST"], "r") as bl: with open(app.config["FHOST_UPLOAD_BLACKLIST"], "r") as bl:
for l in bl.readlines(): for l in bl.readlines():
if not l.startswith("#"): if not l.startswith("#"):
if not ":" in l: if not ":" in l:
queryaddr("::ffff:" + l.rstrip(), nsfw) blist.append("::ffff:" + l.rstrip())
else: 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__": if __name__ == "__main__":
manager.run() manager.run()