Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/App/Controllers/PackageController+routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ enum PackageController {
documentationMetadata: documentationMetadata
)

case .css, .data, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .svgImages, .svgImg:
case .css, .data, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .svgImages, .svgImg, .videos:
return try await res.encodeResponse(
status: .ok,
headers: req.headers
Expand Down Expand Up @@ -448,7 +448,7 @@ extension PackageController {
let path = route.path

switch route.fragment {
case .css, .data, .documentation, .images, .img, .index, .js, .tutorials, .svgImages, .svgImg:
case .css, .data, .documentation, .images, .img, .index, .js, .tutorials, .svgImages, .svgImg, .videos:
return URI(string: "\(baseURL)/\(route.fragment.urlFragment)/\(path)")
case .faviconIco, .faviconSvg, .themeSettings:
return path.isEmpty
Expand Down
7 changes: 4 additions & 3 deletions Sources/App/Core/DocRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ struct DocRoute: Equatable {
case tutorials
case svgImages
case svgImg
case videos

var contentType: String {
switch self {
case .css:
return "text/css"
case .data, .faviconIco, .faviconSvg, .images, .img, .index:
case .data, .faviconIco, .faviconSvg, .images, .img, .index, .videos:
return "application/octet-stream"
case .linkablePaths, .themeSettings:
return "application/json"
Expand All @@ -57,7 +58,7 @@ struct DocRoute: Equatable {

var requiresArchive: Bool {
switch self {
case .css, .data, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .tutorials, .svgImages, .svgImg:
case .css, .data, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .tutorials, .svgImages, .svgImg, .videos:
return false
case .documentation:
return true
Expand All @@ -66,7 +67,7 @@ struct DocRoute: Equatable {

var urlFragment: String {
switch self {
case .css, .data, .documentation, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .tutorials:
case .css, .data, .documentation, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .tutorials, .videos:
return rawValue
case .svgImages:
return "images"
Expand Down
6 changes: 5 additions & 1 deletion Sources/App/routes+documentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func docRoutes(_ app: Application) throws {
let route = try await $0.getDocRoute(fragment: .tutorials)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
app.get(":owner", ":repository", ":reference", "videos", "**") {
let route = try await $0.getDocRoute(fragment: .videos)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}


Expand All @@ -111,7 +115,7 @@ private extension Parameters {
// AND THE FIX
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/pull/3039
return ([archive].compactMap { $0 } + getCatchall()).map { $0.lowercased() }
case .css, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .svgImages, .svgImg:
case .css, .faviconIco, .faviconSvg, .images, .img, .index, .js, .linkablePaths, .themeSettings, .svgImages, .svgImg, .videos:
return getCatchall()
}
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/AppTests/RoutesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ final class RoutesTests: AppTestCase {
}
}

func test_documentation_videos() async throws {
try await withDependencies {
$0.environment.awsDocsBucket = { "docs-bucket" }
} operation: {
// setup
Current.fetchDocumentation = { _, _ in .init(status: .ok) }

// MUT
try await app.test(.GET, "foo/bar/1.2.3/videos/baz.mov") { res async in
// validation
XCTAssertEqual(res.status, .ok)
}
}
}

func test_openapi() async throws {
try await app.test(.GET, "openapi/openapi.json") { res async in
XCTAssertEqual(res.status, .ok)
Expand Down
Loading