接入在线 LUT 权限、登录与服务器帧预览初版,待正式验收

这个提交包含在:
mac 于 2026-11-11 18:25:35 +08:00 提交
1 父节点 f7d0a80a2e
当前提交 a2a8624dc0
12 个文件已更改
+938 -18

没有与搜索条件相匹配的文件

+41
查看文件
@@ -1,4 +1,5 @@
#import "DYLUTLibrary.h"
#import <CommonCrypto/CommonDigest.h>
#include <algorithm>
#include <charconv>
#include <string_view>
@@ -530,6 +531,46 @@ static BOOL DYLUTEnsureDirectory(NSURL *directory,NSURL *root,NSError **error) {
NSProgress *progress=[NSProgress discreteProgressWithTotalUnitCount:-1];progress.localizedDescription=@"正在查找 LUT 文件…";NSArray *sources=[[urls copy]autorelease];
dispatch_async(_fileQueue,^{@autoreleasepool{NSError *error=nil;NSArray *imported=[self importURLs:sources progress:progress error:&error];dispatch_async(dispatch_get_main_queue(),^{if(completion)completion(imported,error);});}});return progress;
}
- (NSProgress *)importOnlineData:(NSData *)data identifier:(NSNumber *)identifier name:(NSString *)name category:(NSString *)category checksum:(NSString *)checksum completion:(void (^)(NSString *,NSError *))completion {
NSProgress *progress=[NSProgress progressWithTotalUnitCount:1];progress.localizedDescription=@"正在校验并保存在线 LUT…";
dispatch_async(_fileQueue,^{@autoreleasepool{
NSError *error=nil;NSString *saved=nil;
@synchronized(self->_fileLock){
auto safe=[](NSString *value)->NSString *{
if(![value isKindOfClass:NSString.class])return @"未分类";
NSCharacterSet *bad=[NSCharacterSet characterSetWithCharactersInString:@"/\\:\n\r\t"];
NSString *text=[[[value componentsSeparatedByCharactersInSet:bad]componentsJoinedByString:@" "]stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
while([text hasPrefix:@"."])text=[text substringFromIndex:1];
return text.length?[text substringToIndex:MIN((NSUInteger)60,text.length)]:@"未分类";
};
unsigned char digest[CC_SHA256_DIGEST_LENGTH];CC_SHA256(data.bytes,(CC_LONG)data.length,digest);NSMutableString *hash=[NSMutableString string];for(unsigned char byte:digest)[hash appendFormat:@"%02x",byte];
if(!data.length||data.length>64*1024*1024||identifier.longLongValue<=0||![checksum isKindOfClass:NSString.class]||![hash isEqual:checksum.lowercaseString])DYLUTFail(&error,@"在线 LUT 大小或 SHA-256 校验失败");
NSURL *directory=[self->_rootURL URLByAppendingPathComponent:[@"在线 LUT/" stringByAppendingString:safe(category)] isDirectory:YES];
NSString *filename=[NSString stringWithFormat:@"%@-%@-%@.cube",identifier,safe(name),[hash substringToIndex:12]];
NSURL *destination=[directory URLByAppendingPathComponent:filename];NSURL *temporary=nil;
if(!error&&!DYLUTCancelled(progress,&error)&&DYLUTEnsureDirectory(directory,self->_rootURL,&error)){
NSFileManager *fm=NSFileManager.defaultManager;
if([fm fileExistsAtPath:destination.path]){
BOOL directory=NO;NSData *existing=nil;
if(DYLUTOrdinaryURL(destination,&directory,&error)&&!directory)existing=[NSData dataWithContentsOfURL:destination options:NSDataReadingMappedIfSafe error:&error];
if(directory)DYLUTFail(&error,@"在线 LUT 目标应为普通文件");
if(existing&&![existing isEqualToData:data])DYLUTFail(&error,@"同名在线 LUT 内容不同,已保留现有文件");
}else{
temporary=[directory URLByAppendingPathComponent:[@".online-" stringByAppendingString:NSUUID.UUID.UUIDString]];
if([data writeToURL:temporary options:NSDataWritingWithoutOverwriting error:&error]){
std::vector<float> values;NSUInteger n=0;
if(DYLUTReadCancellable(temporary.path,values,n,progress,&error)&&!DYLUTCancelled(progress,&error))
[fm moveItemAtURL:temporary toURL:destination error:&error];
}
}
if(!error){std::vector<float> values;NSUInteger n=0;if(DYLUTReadCancellable(destination.path,values,n,progress,&error)&&[self reload:&error])saved=destination.path;}
if(temporary)[fm removeItemAtURL:temporary error:nil];
}
}
progress.completedUnitCount=1;
dispatch_async(dispatch_get_main_queue(),^{if(completion)completion(saved,error);});
}});return progress;
}
- (BOOL)isFavoritePath:(NSString *)path {@synchronized(self){return [_favoritePaths containsObject:path];}}
- (BOOL)setFavorite:(BOOL)favorite forPath:(NSString *)path error:(NSError **)error {@synchronized(self){
NSString *prefix=[_rootURL.path stringByAppendingString:@"/"];