Skip to content

Commit 09c111f

Browse files
committed
File streaming service implemented
1 parent a31c6c2 commit 09c111f

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/Boot.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import airpsx.service.pkg.InstallPackageService;
5757
import airpsx.command.ServePackageCommand;
5858
import airpsx.command.KillServePackageCommand;
5959
import uuid.Uuid;
60+
import airpsx.service.filesystem.FileSystemStreamService;
6061
using hx.well.tools.RouteElementTools;
6162

6263
class Boot extends BaseBoot {
@@ -188,6 +189,10 @@ class Boot extends BaseBoot {
188189
.handler(new FileSystemUploadService())
189190
.setStream(true)
190191
.where("path", ".*");
192+
193+
Route.get("/stream/{path}")
194+
.handler(new FileSystemStreamService())
195+
.where("path", ".*");
191196
});
192197

193198
#if orbis
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package airpsx.service.filesystem;
2+
import hx.well.http.Request;
3+
class FileSystemStreamService extends AbstractHttpFileStreamService {
4+
public function filePath(request:Request):String {
5+
return request.route("path");
6+
}
7+
8+
public function bufferSize():Int {
9+
return 1024 * 10;
10+
}
11+
12+
public function contentType(request:Request):String {
13+
var extension = request.path.substring(request.path.lastIndexOf("."));
14+
switch (extension) {
15+
case ".mp4":
16+
return "video/mp4";
17+
case ".webm":
18+
return "video/webm";
19+
default:
20+
return '${extension} undefined';
21+
}
22+
}
23+
24+
public function isDownloadRequest(request:Request):Bool {
25+
return false;
26+
}
27+
28+
public function basePath():Null<String> {
29+
return null;
30+
}
31+
}

0 commit comments

Comments
 (0)