Skip to content

Commit

Permalink
下载服务
Browse files Browse the repository at this point in the history
  • Loading branch information
togettoyou committed Feb 28, 2022
1 parent 413871d commit 09fb02f
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 23 deletions.
62 changes: 54 additions & 8 deletions server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ var doc = `{
},
"/api/v1/download/icon/{uuid}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
Expand Down Expand Up @@ -259,18 +254,69 @@ var doc = `{
},
"/api/v1/download/mobileConfig/{uuid}": {
"get": {
"security": [
"produces": [
"application/json"
],
"tags": [
"Download"
],
"summary": "下载mobileconfig服务",
"parameters": [
{
"ApiKeyAuth": []
"type": "string",
"description": "uuid",
"name": "uuid",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.Response"
}
}
}
}
},
"/api/v1/download/plist/{uuid}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Download"
],
"summary": "下载Plist服务",
"parameters": [
{
"type": "string",
"description": "uuid",
"name": "uuid",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.Response"
}
}
}
}
},
"/api/v1/download/tempipa/{uuid}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Download"
],
"summary": "下载mobileconfig服务",
"summary": "下载TempIPA服务",
"parameters": [
{
"type": "string",
Expand Down
62 changes: 54 additions & 8 deletions server/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@
},
"/api/v1/download/icon/{uuid}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
Expand Down Expand Up @@ -241,18 +236,69 @@
},
"/api/v1/download/mobileConfig/{uuid}": {
"get": {
"security": [
"produces": [
"application/json"
],
"tags": [
"Download"
],
"summary": "下载mobileconfig服务",
"parameters": [
{
"ApiKeyAuth": []
"type": "string",
"description": "uuid",
"name": "uuid",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.Response"
}
}
}
}
},
"/api/v1/download/plist/{uuid}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Download"
],
"summary": "下载Plist服务",
"parameters": [
{
"type": "string",
"description": "uuid",
"name": "uuid",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.Response"
}
}
}
}
},
"/api/v1/download/tempipa/{uuid}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Download"
],
"summary": "下载mobileconfig服务",
"summary": "下载TempIPA服务",
"parameters": [
{
"type": "string",
Expand Down
40 changes: 36 additions & 4 deletions server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ paths:
description: OK
schema:
$ref: '#/definitions/api.Response'
security:
- ApiKeyAuth: []
summary: 下载icon服务
tags:
- Download
Expand Down Expand Up @@ -195,11 +193,45 @@ paths:
description: OK
schema:
$ref: '#/definitions/api.Response'
security:
- ApiKeyAuth: []
summary: 下载mobileconfig服务
tags:
- Download
/api/v1/download/plist/{uuid}:
get:
parameters:
- description: uuid
in: path
name: uuid
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/api.Response'
summary: 下载Plist服务
tags:
- Download
/api/v1/download/tempipa/{uuid}:
get:
parameters:
- description: uuid
in: path
name: uuid
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/api.Response'
summary: 下载TempIPA服务
tags:
- Download
/api/v1/ipa:
delete:
parameters:
Expand Down
76 changes: 73 additions & 3 deletions server/internal/api/v1/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,43 @@ const (
<key>PayloadType</key>
<string>Profile Service</string>
</dict>
</plist>`
plistTemp = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>{{ .URL }}</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>{{ .BundleIdentifier }}</string>
<key>bundle-version</key>
<string>{{ .Version }}</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>{{ .Name }}</string>
</dict>
</dict>
</array>
</dict>
</plist>`
)

// MobileConfig
// @Tags Download
// @Summary 下载mobileconfig服务
// @Security ApiKeyAuth
// @Produce json
// @Param uuid path string true "uuid"
// @Success 200 {object} api.Response
Expand All @@ -76,8 +106,32 @@ func (d Download) MobileConfig(c *gin.Context) {
}
}

// Plist
// @Tags Download
// @Summary 下载Plist服务
// @Produce json
// @Param uuid path string true "uuid"
// @Success 200 {object} api.Response
// @Router /api/v1/download/plist/{uuid} [get]
func (d Download) Plist(c *gin.Context) {

var args req.DownloadUri
if !d.MakeContext(c).ParseUri(&args) {
return
}
tmpl, err := template.New(args.UUID).Parse(plistTemp)
if d.HasErr(err) {
return
}
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename="+args.UUID+".plist")
if d.HasErr(tmpl.Execute(c.Writer, map[string]string{
"URL": "",
"BundleIdentifier": "",
"Version": "",
"Name": "",
})) {
return
}
}

// IPA
Expand All @@ -98,10 +152,26 @@ func (d Download) IPA(c *gin.Context) {
c.File(path.Join(conf.Apple.UploadFilePath, args.UUID, "ipa.ipa"))
}

// TempIPA
// @Tags Download
// @Summary 下载TempIPA服务
// @Produce json
// @Param uuid path string true "uuid"
// @Success 200 {object} api.Response
// @Router /api/v1/download/tempipa/{uuid} [get]
func (d Download) TempIPA(c *gin.Context) {
var args req.DownloadUri
if !d.MakeContext(c).ParseUri(&args) {
return
}
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename="+args.UUID+".ipa")
c.File(path.Join(conf.Apple.TemporaryFilePath, args.UUID, "ipa.ipa"))
}

// Icon
// @Tags Download
// @Summary 下载icon服务
// @Security ApiKeyAuth
// @Produce json
// @Param uuid path string true "uuid"
// @Success 200 {object} api.Response
Expand Down
2 changes: 2 additions & 0 deletions server/internal/server/router/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func registerDownloadRouter(store *model.Store, r *gin.RouterGroup) {

{
downloadR.GET("mobileConfig/:uuid", download.MobileConfig)
downloadR.GET("plist/:uuid", download.Plist)
downloadR.GET("ipa/:uuid", download.IPA)
downloadR.GET("tempipa/:uuid", download.TempIPA)
downloadR.GET("icon/:uuid", download.Icon)
}
}

0 comments on commit 09fb02f

Please sign in to comment.