assets: return asset URL as response of "set" API (#64970)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Frédéric Péters 2022-05-06 21:12:05 +02:00
parent 72a5123831
commit 4f9abf2d00
2 changed files with 3 additions and 1 deletions

View File

@ -55,7 +55,7 @@ class Set(GenericAPIView):
asset, dummy = Asset.objects.get_or_create(key=key)
asset.asset = File(BytesIO(data['asset']['content']), name=data['asset'].get('filename'))
asset.save()
response = {'err': 0}
response = {'err': 0, 'url': request.build_absolute_uri(f'/assets/{key}')}
return Response(response)

View File

@ -59,6 +59,8 @@ def test_asset_set_api(app, john_doe):
}
},
)
assert resp.json.get('err') == 0
assert resp.json.get('url') == 'http://testserver/assets/plop'
assert Asset.objects.get(key='plop').asset.read() == b'plop2'
resp = app.post_json(reverse('api-assets-set', kwargs={'key': 'plop'}), params={}, status=400)