管理后台增加应用原包下载功能

publicsignpoll
youngS 3 years ago
parent 2feda8800c
commit 439db9788a
  1. 7
      fir_admin/src/api/app.js
  2. 23
      fir_admin/src/views/appinfos/AppReleaseList.vue
  3. 36
      fir_ser/admin/views/app.py

@ -39,3 +39,10 @@ export function updateReleaseAppInfo(data) {
data
})
}
export function downloadAppReleaseInfos(data) {
return request({
url: '/app/release/info',
method: 'post',
data
})
}

@ -67,13 +67,16 @@
</el-tooltip>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
<el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
<template slot-scope="scope">
<router-link :to="{name: 'app_release_info_edit',params:{app_id:listQuery.app_id,id:scope.row.id}}">
<el-button type="primary" size="mini">
查看编辑
</el-button>
</router-link>
<el-button type="info" size="mini" @click="download_bin(scope.row)">
下载源文件
</el-button>
</template>
</el-table-column>
</el-table>
@ -83,7 +86,7 @@
</template>
<script>
import { getAppReleaseInfos } from '@/api/app'
import { getAppReleaseInfos, downloadAppReleaseInfos } from '@/api/app'
import { baseFilter } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import waves from '@/directive/waves' // waves directive
@ -130,6 +133,7 @@ export default {
page: 1,
limit: 10,
app_id: undefined,
download_token: undefined,
release_id: undefined,
sort: '-created_time'
},
@ -143,6 +147,21 @@ export default {
this.fetchData()
},
methods: {
download_bin(app_info) {
downloadAppReleaseInfos(
{
'token': app_info.download_token,
'release_id': app_info.release_id,
'app_id': app_info.app_id
}
).then(res => {
if (res.code === 1000) {
window.location.href = res.data.download_url
} else {
this.$message.error(res.msg)
}
})
},
handleFilter() {
this.listQuery.page = 1
this.fetchData()

@ -7,6 +7,8 @@
from django.contrib import auth
from api.models import Token, AppReleaseInfo, Apps
from rest_framework.response import Response
from api.utils.TokenManager import verify_token
from api.utils.auth import AdminTokenAuthentication
from api.utils.serializer import AdminAppsSerializer, AdminAppReleaseSerializer
from django.core.cache import cache
@ -16,7 +18,8 @@ import os, datetime
from api.utils.utils import get_captcha, valid_captcha, get_choices_dict
from api.utils.response import BaseResponse
from fir_ser.settings import CACHE_KEY_TEMPLATE, LOGIN
from api.utils.storage.caches import login_auth_failed, del_cache_response_by_short
from api.utils.storage.caches import login_auth_failed, del_cache_response_by_short, get_app_instance_by_cache, \
get_download_url_by_cache
import logging
from api.utils.throttle import VisitRegister1Throttle, VisitRegister2Throttle
from rest_framework.pagination import PageNumberPagination
@ -125,3 +128,34 @@ class AppReleaseInfoView(APIView):
res.code = 1004
res.msg = "数据校验失败"
return Response(res.dict)
def post(self, request):
res = BaseResponse()
data = request.data
downtoken = data.get("token", None)
app_id = data.get("app_id", None)
release_id = data.get("release_id", None)
if not downtoken or not app_id or not release_id:
res.code = 1004
res.msg = "参数丢失"
return Response(res.dict)
if verify_token(downtoken, release_id):
app_obj = Apps.objects.filter(pk=app_id).values("pk", 'user_id', 'type').first()
release_obj = AppReleaseInfo.objects.filter(app_id=app_id, release_id=release_id).count()
if app_obj and release_obj:
if app_obj.get("type") == 0:
app_type = '.apk'
else:
app_type = '.ipa'
download_url, extra_url = get_download_url_by_cache(app_obj, release_id + app_type, 600)
res.data = {"download_url": download_url, "extra_url": extra_url}
return Response(res.dict)
else:
res.code = 1004
res.msg = "token校验失败"
return Response(res.dict)
res.code = 1006
res.msg = "该应用不存在"
return Response(res.dict)

Loading…
Cancel
Save