syntax = "proto3";
package files;

option go_package = "./;files";


service File{
    rpc List(FileListReq) returns (FileListResp) {} // 获取当前路径下的文件列表
    rpc Info(FileInfoReq) returns (FileInfoResp) {} // 获取文件信息
    rpc Create(CreateReq) returns (CreateResp) {} // 创建文件夹
    rpc Delete(DeleteReq) returns (DeleteResp) {} // 删除文件或文件夹
    rpc Search(searchReq) returns (searchResp) {} // 搜索
    rpc Upload(UploadReq) returns (UploadResp) {} // 文件上传
    rpc TusCreate(TusCreateReq) returns (TusCreateResp) {} // 分块文件上传：创建文件
    rpc TusUpload(TusUploadReq) returns (TusUploadResp) {} // 分块文件上传：上传文件块
    rpc ResumableTransfer(ResumableTransferReq) returns (ResumableTransferResp) {} // 断点续传的grpc实现
    rpc Preview(PreviewReq) returns (PreviewResp) {} // 文件预览
    rpc Action(ActionReq) returns (ActionResp) {} // 移动文件或重命名文件
    rpc DirDownload(DirDownloadReq) returns (stream DirDownloadResp) {} // 文件夹压缩下载
} 

message FileListReq{
    string path = 1; // 目标文件夹路径
    string userSpacePath = 2; // 用户空间的路径
    Sorting sorting = 3;  
}

message Items {
    string path = 1;
    string name = 2;
    int64 size = 3;
    string extension = 4;
    string modified = 5;
    int64 modTime = 6;
    string mode = 7;
    bool isDir = 8;
    bool isSymlink = 9;
    string type = 10;
}

message Sorting {
    string by = 1;
    bool asc = 2;
}

message FileListResp {
    repeated Items items = 1;
    int32 numDirs = 2;
    int32 numFiles = 3;
    Sorting sorting = 4;
    string path = 5;
    string name = 6;
    int64 size = 7;
    string extension = 8;
    string modified = 9;
    int64 modTime = 10;
    string mode = 11;
    bool isDir = 12;
    bool isSymlink = 13;
    string type = 14;
}


message CreateReq{
    string path = 1;
    string userSpacePath = 2;
}

message CreateResp{

}


message DeleteReq{
    string path = 1;
    string userSpacePath = 2;
}

message DeleteResp{

}

message UploadReq{
    string path = 1;
    string userSpacePath = 2;
    bytes content =3;

}

message UploadResp{

}

message searchReq{
    string path = 1;
    string userSpacePath = 2;
    string query = 3;
}

message searchResp{
    message Nested {
        bool dir = 1;
        string path = 2;
    }

    repeated Nested items = 1;
}


message TusCreateReq{
    string path = 1;
    string userSpacePath = 2;
    bool override =3 ;
}

message TusCreateResp{
    int64 uploadLength  = 1;
    int64 uploadOffset = 2;
}

message TusUploadReq{
    string path = 1;
    string userSpacePath = 2;
    int64 uploadOffset = 3;
    bytes content = 4;
}

message TusUploadResp{
    int64 uploadOffset = 1;
}

message ResumableTransferReq{
    string path = 1;
    string userSpacePath = 2;
    int64 offset = 3;
    int64 length = 4;
}

message ResumableTransferResp{
    bytes content = 1;
}

message FileInfoReq{
    string path = 1;
    string userSpacePath = 2;
}

message FileInfoResp{
    string path = 1;
    string name = 2;
    int64 size = 3;
    string extension = 4;
    string modified = 5;
    string mode = 6;
    int64 modTime = 7;
    bool isDir = 8;
    bool isSymlink = 9;
    string type = 10;
}

message PreviewReq{
    string path = 1;
    string userSpacePath = 2;
    uint32 size = 3; // 预览大小 0：256x256, 1:1080x1080
}

message PreviewResp{
    bytes content = 1;
    string fileName = 2;
    int64 modTime = 3; 
}

message ActionReq{
    string path = 1;
    string userSpacePath = 2;
    string action = 3;
    string destination = 4;
    bool override = 5;
    bool rename = 6;
}

message ActionResp{

}

message DirDownloadReq {
    string path = 1;
    string userSpacePath = 2;
    repeated string files =3;
    string algo = 4;
    
}

message DirDownloadResp {
    bytes content = 1;
}
