(ctx context.Context, data wshrpc.CommandWaveFileReadStreamData)
| 1033 | } |
| 1034 | |
| 1035 | func (ws *WshServer) WaveFileReadStreamCommand(ctx context.Context, data wshrpc.CommandWaveFileReadStreamData) (*wshrpc.WaveFileInfo, error) { |
| 1036 | const maxStreamFileSize = 5 * 1024 * 1024 |
| 1037 | |
| 1038 | waveFile, err := filestore.WFS.Stat(ctx, data.ZoneId, data.Name) |
| 1039 | if err != nil { |
| 1040 | return nil, fmt.Errorf("error statting wavefile: %w", err) |
| 1041 | } |
| 1042 | |
| 1043 | dataLength := waveFile.DataLength() |
| 1044 | if dataLength > maxStreamFileSize { |
| 1045 | return nil, fmt.Errorf("file size %d exceeds maximum streaming size of %d bytes", dataLength, maxStreamFileSize) |
| 1046 | } |
| 1047 | |
| 1048 | wshRpc := wshutil.GetWshRpcFromContext(ctx) |
| 1049 | if wshRpc == nil || wshRpc.StreamBroker == nil { |
| 1050 | return nil, fmt.Errorf("no stream broker available") |
| 1051 | } |
| 1052 | |
| 1053 | writer, err := wshRpc.StreamBroker.CreateStreamWriter(&data.StreamMeta) |
| 1054 | if err != nil { |
| 1055 | return nil, fmt.Errorf("error creating stream writer: %w", err) |
| 1056 | } |
| 1057 | |
| 1058 | _, fileData, err := filestore.WFS.ReadFile(ctx, data.ZoneId, data.Name) |
| 1059 | if err != nil { |
| 1060 | writer.Close() |
| 1061 | return nil, fmt.Errorf("error reading wavefile: %w", err) |
| 1062 | } |
| 1063 | |
| 1064 | go func() { |
| 1065 | defer func() { |
| 1066 | panichandler.PanicHandler("WaveFileReadStreamCommand", recover()) |
| 1067 | }() |
| 1068 | defer writer.Close() |
| 1069 | |
| 1070 | _, err := writer.Write(fileData) |
| 1071 | if err != nil { |
| 1072 | log.Printf("error writing to stream for wavefile %s:%s: %v\n", data.ZoneId, data.Name, err) |
| 1073 | } |
| 1074 | }() |
| 1075 | |
| 1076 | rtnInfo := &wshrpc.WaveFileInfo{ |
| 1077 | ZoneId: waveFile.ZoneId, |
| 1078 | Name: waveFile.Name, |
| 1079 | Opts: waveFile.Opts, |
| 1080 | CreatedTs: waveFile.CreatedTs, |
| 1081 | Size: waveFile.Size, |
| 1082 | ModTs: waveFile.ModTs, |
| 1083 | Meta: waveFile.Meta, |
| 1084 | } |
| 1085 | return rtnInfo, nil |
| 1086 | } |
| 1087 | |
| 1088 | func (ws *WshServer) WriteAppGoFileCommand(ctx context.Context, data wshrpc.CommandWriteAppGoFileData) (*wshrpc.CommandWriteAppGoFileRtnData, error) { |
| 1089 | if data.AppId == "" { |
nothing calls this directly
no test coverage detected