Skip to content

Commit

Permalink
查看某版本号下所有文件 link #36
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonczc committed Nov 1, 2021
1 parent e4607db commit e75e43d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
24 changes: 20 additions & 4 deletions server/src/controller/PluginsController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,27 @@ class PluginsController(
return r.ok()
}

@ApiOperation("查看目标版本的所有文件")
@GetMapping("/{id}/{version}")
@ApiResponses(
ApiResponse(code = 404, message = "Version not found", response = ApiResp::class),
)
fun (@receiver:ApiIgnore ServerWebExchange).getVersionFiles(
@ApiParam("插件 ID", example = PluginDesc.ID_EXAMPLE)
@PathVariable
id: String,
@ApiParam("插件 ID", example = PluginDesc.VERSION_EXAMPLE)
@PathVariable
version: String
): ApiResp<Array<String>?> {
desc.get(id) ?: return r.notFound(null)
if(!storage.hasVersion(id,version)) return r(404)
return r.ok(storage.getVersionFiles(id,version))
}

@ApiOperation("查看版本列表")
@GetMapping("/{id}/versionList")
@ApiResponses(
ApiResponse(code = 403, message = "Plugin is not owned by you", response = ApiResp::class),
ApiResponse(code = 404, message = "Version not found", response = ApiResp::class),
)
fun (@receiver:ApiIgnore ServerWebExchange).getVersionList(
Expand All @@ -239,8 +256,7 @@ class PluginsController(
id: String
): ApiResp<Array<String>?> {
desc.get(id) ?: return r.notFound(null)
val result = storage.getVersionList(id)?: arrayOf()
return r.ok(result)
return r.ok(storage.getVersionList(id))
}

@ApiOperation("删除一个版本及该版本下的所有文件")
Expand All @@ -254,7 +270,7 @@ class PluginsController(
@PathVariable
id: String,

@ApiParam("插件版本号")
@ApiParam("插件版本号", example = PluginDesc.VERSION_EXAMPLE)
@PathVariable
version: String,
): ApiResp<Void?> {
Expand Down
1 change: 1 addition & 0 deletions server/src/dto/PluginDesc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ data class PluginDesc(
const val ID_EXAMPLE = "org.example.mirai.test-plugin"
const val NAME_EXAMPLE = "A Simple Test Plugin"
const val INFO_EXAMPLE = "This is a sample plugin providing some features."
const val VERSION_EXAMPLE = "1.0.0"
}
}

Expand Down
8 changes: 6 additions & 2 deletions server/src/services/PluginStorageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ class PluginStorageService {
return resolveVersionDir(pid, version).exists()
}

fun getVersionList(pid: String): Array<String>? {
return resolvePluginDir(pid).list()
fun getVersionFiles(pid: String, version: String): Array<String> {
return resolveVersionDir(pid, version).list()?: arrayOf()
}

fun getVersionList(pid: String): Array<String> {
return resolvePluginDir(pid).list()?: arrayOf()
}

fun addVersion(pid: String, version: String): Boolean {
Expand Down

0 comments on commit e75e43d

Please sign in to comment.