-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of private:sdcb/chats into dev
- Loading branch information
Showing
11 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Chats.BE.DB; | ||
|
||
public partial class ModelReference | ||
{ | ||
public float? UnnormalizeTemperature(float? temperature) | ||
{ | ||
if (temperature == null) return null; | ||
return temperature * (float)(MaxTemperature - MinTemperature) + (float)MinTemperature; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
namespace Chats.BE.Services.FileServices; | ||
|
||
/// <summary> | ||
/// Interface for file service operations such as upload, download, and creating download URLs. | ||
/// </summary> | ||
public interface IFileService | ||
{ | ||
/// <summary> | ||
/// Uploads a file to the storage. The caller must dispose the stream. | ||
/// </summary> | ||
/// <param name="request">The file upload request containing file details.</param> | ||
/// <param name="cancellationToken">Token to monitor for cancellation requests.</param> | ||
/// <returns>A task that represents the asynchronous operation. The task result contains the storage key of the uploaded file.</returns> | ||
/// <remarks> | ||
/// The <see cref="Stream"/> inside <see cref="FileUploadRequest"/> will not be disposed by the file service. | ||
/// </remarks> | ||
Task<string> Upload(FileUploadRequest request, CancellationToken cancellationToken); | ||
|
||
/// <summary> | ||
/// Downloads a file from the storage. | ||
/// </summary> | ||
/// <param name="storageKey">The storage key of the file to download.</param> | ||
/// <param name="cancellationToken">Token to monitor for cancellation requests.</param> | ||
/// <returns> | ||
/// A task that represents the asynchronous operation. The task result contains the file stream. | ||
/// The caller must dispose the stream. | ||
/// </returns> | ||
Task<Stream> Download(string storageKey, CancellationToken cancellationToken); | ||
|
||
/// <summary> | ||
/// Creates a download URL for a file. | ||
/// </summary> | ||
/// <param name="request">The request containing details for creating the download URL.</param> | ||
/// <returns>The URI of the created download URL.</returns> | ||
Uri CreateDownloadUrl(CreateDownloadUrlRequest request); | ||
} |
17 changes: 12 additions & 5 deletions
17
src/BE/Services/FileServices/Implementations/AliyunOSS/AliyunOSSFileService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
| ||
using Aliyun.OSS; | ||
|
||
namespace Chats.BE.Services.FileServices.Implementations.AliyunOSS; | ||
|
||
public class AliyunOSSFileService(AliyunOssConfig aliyunOssConfig) : IFileService | ||
public class AliyunOSSFileService(AliyunOssConfig config) : IFileService | ||
{ | ||
private readonly OssClient _oss = new(config.Endpoint, config.AccessKeyId, config.AccessKeySecret); | ||
|
||
public Uri CreateDownloadUrl(CreateDownloadUrlRequest req) | ||
{ | ||
throw new NotImplementedException(); | ||
return _oss.GeneratePresignedUri(config.Bucket, req.StorageKey, req.ValidEnd, SignHttpMethod.Get); | ||
} | ||
|
||
public Task<Stream> Download(string storageKey, CancellationToken cancellationToken) | ||
{ | ||
throw new NotImplementedException(); | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
OssObject obj = _oss.GetObject(config.Bucket, storageKey); | ||
return Task.FromResult(obj.ResponseStream); | ||
} | ||
|
||
public Task<string> Upload(FileUploadRequest request, CancellationToken cancellationToken) | ||
{ | ||
throw new NotImplementedException(); | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
SuggestedStorageInfo ssi = SuggestedStorageInfo.FromFileName(request.FileName); | ||
_ = _oss.PutObject(config.Bucket, ssi.StorageKey, request.Stream); | ||
return Task.FromResult(ssi.StorageKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters