示例#1
0
async def get_token_set_html(
        uuid: UUID,
        response: Response,
        manager: MapSetManager = Depends(get_map_set_manager),
):
    map_set = get_map_set(manager, uuid)
    return map_set.token_set_html
示例#2
0
async def delete_battle_map(
        data: BattleMapDeleteRequest,
        manager: MapSetManager = Depends(get_map_set_manager),
):
    map_set = get_map_set(manager, data.map_set_uuid)
    battle_map = get_battle_map(manager, data.map_set_uuid, data.uuid)
    manager.delete_battle_map(map_set, battle_map)
    manager.save(map_set)
示例#3
0
async def create_battle_map(
        data: BattleMapCreateRequest,
        manager: MapSetManager = Depends(get_map_set_manager),
) -> BattleMapInfo:
    map_set = get_map_set(manager, data.map_set_uuid)
    battle_map = map_set.add_new_battle_map(data.name)
    manager.save(map_set)
    return BattleMapInfo(map_set_uuid=map_set.uuid, **battle_map.__dict__)
示例#4
0
async def update_map_set(
    data: MapSetUpdateRequest,
    manager: MapSetManager = Depends(get_map_set_manager),
    directory: MapSetDirectory = Depends(get_map_set_directory),
    _: None = Depends(check_admin_secret)):
    map_set = get_map_set(manager, data.uuid)
    map_set.name = data.name
    directory.delete(map_set)
    directory.add(map_set)
    manager.save(map_set)
示例#5
0
async def update_battle_map(
        data: BattleMapUpdateRequest,
        manager: MapSetManager = Depends(get_map_set_manager),
) -> BattleMapInfo:
    map_set = get_map_set(manager, data.map_set_uuid)
    battle_map = get_battle_map(manager, data.map_set_uuid, data.uuid)

    battle_map.name = data.name
    battle_map.background_pixels_per_meter = data.background_pixels_per_meter

    battle_map.signal_update()
    manager.save(map_set)
    return BattleMapInfo(map_set_uuid=map_set.uuid, **battle_map.__dict__)
示例#6
0
def download_map_set(
        uuid: UUID,
        manager: MapSetManager = Depends(get_map_set_manager),
        backup_io: BackupIo = Depends(get_backup_io),
) -> Response:
    map_set = get_map_set(manager, uuid)
    filename = _get_safe_file_name(map_set.name)
    buffer = BytesIO()
    backup_io.export_map_set_tar_gz(uuid, buffer)
    buffer.seek(0)
    response = StreamingResponse(buffer,
                                 media_type="application/open-battle-map")
    response.headers[
        'Content-Disposition'] = f'attachment; filename="{filename}"'
    return response
async def upload_image_data(
        image_data: UploadFile = File(...),
        uuid: UUID = Form(...),
        map_set_uuid: UUID = Form(...),
        manager: MapSetManager = Depends(get_map_set_manager),
):
    image_media_type_validator(image_data.content_type)
    map_set = get_map_set(manager, map_set_uuid)
    battle_map = get_battle_map(manager, map_set_uuid, uuid)
    data = await image_data.read()
    battle_map.set_background_image(data, image_data.content_type)
    manager.save_background(battle_map)
    manager.sanitize_token_positions(battle_map)
    battle_map.signal_update()
    manager.save(map_set)
示例#8
0
async def map_set_info(
    uuid: UUID,
    response: Response,
    obm_known_map_sets: str = Cookie(''),
    manager: MapSetManager = Depends(get_map_set_manager),
    directory: MapSetDirectory = Depends(get_map_set_directory),
    config: Config = Depends(get_config)
) -> MapSetInfoResponse:
    map_set = get_map_set(manager, uuid)
    response.headers['Cache-Control'] = 'no-cache'
    _update_known_map_sets_cookie(map_set_uuid=uuid,
                                  old_cookie=obm_known_map_sets,
                                  response=response,
                                  config=config,
                                  directory=directory)
    return MapSetInfoResponse(name=map_set.name,
                              uuid=map_set.uuid,
                              battle_maps=_get_battle_maps(map_set),
                              token_set=map_set.token_set)
示例#9
0
async def delete_map_set(data: MapSetDeleteRequest,
                         manager: MapSetManager = Depends(get_map_set_manager),
                         _: None = Depends(check_admin_secret)):
    map_set = get_map_set(manager, data.uuid)
    manager.delete(map_set)