mirror of
https://git.0x0.st/mia/0x0.git
synced 2024-11-22 16:57:12 +01:00
Refactor min_length of urls
This commit is contained in:
parent
2f063811fc
commit
67287ab451
1 changed files with 7 additions and 6 deletions
13
fhost.py
13
fhost.py
|
@ -98,7 +98,7 @@ class URL(db.Model):
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
def getname(self):
|
def getname(self):
|
||||||
return su.enbase(self.id, 1)
|
return su.enbase(self.id)
|
||||||
|
|
||||||
def geturl(self):
|
def geturl(self):
|
||||||
return url_for("get", path=self.getname(), _external=True) + "\n"
|
return url_for("get", path=self.getname(), _external=True) + "\n"
|
||||||
|
@ -129,7 +129,7 @@ class File(db.Model):
|
||||||
self.addr = addr
|
self.addr = addr
|
||||||
|
|
||||||
def getname(self):
|
def getname(self):
|
||||||
return u"{0}{1}".format(su.enbase(self.id, 1), self.ext)
|
return u"{0}{1}".format(su.enbase(self.id), self.ext)
|
||||||
|
|
||||||
def geturl(self):
|
def geturl(self):
|
||||||
n = self.getname()
|
n = self.getname()
|
||||||
|
@ -207,16 +207,17 @@ class File(db.Model):
|
||||||
|
|
||||||
|
|
||||||
class UrlEncoder(object):
|
class UrlEncoder(object):
|
||||||
def __init__(self,alphabet):
|
def __init__(self,alphabet, min_length):
|
||||||
self.alphabet = alphabet
|
self.alphabet = alphabet
|
||||||
|
self.min_length = min_length
|
||||||
|
|
||||||
def enbase(self, x, min_length):
|
def enbase(self, x):
|
||||||
n = len(self.alphabet)
|
n = len(self.alphabet)
|
||||||
str = ""
|
str = ""
|
||||||
while x > 0:
|
while x > 0:
|
||||||
str = (self.alphabet[int(x % n)]) + str
|
str = (self.alphabet[int(x % n)]) + str
|
||||||
x = int(x // n)
|
x = int(x // n)
|
||||||
padding = self.alphabet[0] * (min_length - len(str))
|
padding = self.alphabet[0] * (self.min_length - len(str))
|
||||||
return '%s%s' % (padding, str)
|
return '%s%s' % (padding, str)
|
||||||
|
|
||||||
def debase(self, x):
|
def debase(self, x):
|
||||||
|
@ -226,7 +227,7 @@ class UrlEncoder(object):
|
||||||
result += self.alphabet.index(c) * (n ** i)
|
result += self.alphabet.index(c) * (n ** i)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
su = UrlEncoder(alphabet=app.config["URL_ALPHABET"])
|
su = UrlEncoder(alphabet=app.config["URL_ALPHABET"], min_length=1)
|
||||||
|
|
||||||
def fhost_url(scheme=None):
|
def fhost_url(scheme=None):
|
||||||
if not scheme:
|
if not scheme:
|
||||||
|
|
Loading…
Reference in a new issue