18 lines
473 B
Python
18 lines
473 B
Python
import zlib
|
|
from .models import Map
|
|
from .schemas import MapOut
|
|
import copy
|
|
from .config import config
|
|
|
|
|
|
def crc32(bytes_in: bytes) -> int:
|
|
return zlib.crc32(bytes_in, 0) & 0xffffffff
|
|
|
|
|
|
def map_model_to_out_schema(map_in: Map) -> MapOut:
|
|
d = copy.deepcopy(map_in.__dict__)
|
|
d["crc_human"] = hex(map_in.crc)[2:].upper()
|
|
d["blob_location"] = "%s/%s%s" % (config["base_url"], config["upload_path"], map_in.filename)
|
|
map_out = MapOut(**d)
|
|
return map_out
|