删除测试数据

This commit is contained in:
2025-11-12 15:40:30 +08:00
parent c317afc0fe
commit 62f3ddae4a

View File

@@ -85,7 +85,6 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
- (void)dealloc {
[self stopPasteboardMonitor];
[self kb_stopNetworkStreaming];
[self kb_stopMockStreaming];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@@ -241,13 +240,12 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
self.streamDeleteButton = del;
// GET
[self kb_startNetworkStreamingWithSeed:title fallbackToMock:YES];
[self kb_startNetworkStreamingWithSeed:title];
}
- (void)kb_onTapStreamDelete {
//
[self kb_stopNetworkStreaming];
[self kb_stopMockStreaming];
[self.streamDeleteButton removeFromSuperview];
self.streamDeleteButton = nil;
[self.streamTextView removeFromSuperview];
@@ -255,67 +253,18 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
self.collectionViewInternal.hidden = NO;
}
#pragma mark - Mock Streaming
// KBStreamTextView
- (void)kb_startMockStreamingWithSeed:(NSString *)seedTitle {
[self kb_stopMockStreaming];
// \t \n 1~3
NSString *t = seedTitle ?: @"高情商";
self.streamMockSource = [NSString stringWithFormat:
@"选择了标签:%@\n"
"下面演示流式输出,每隔一小段时间来一截。第一段结束。\t"
"第二段开始:这是一个较长的句子,会被拆成多个小块推送,直到遇到分隔符就换段。\n第二段结束。\t"
"最后一段:右上角可随时关闭展示。\n演示完成。\t",
t];
self.streamMockCursor = 0;
self.streamMockChunks = nil; //
self.streamMockIndex = 0;
// 线 1~3
__weak typeof(self) weakSelf = self;
self.streamMockTimer = [NSTimer scheduledTimerWithTimeInterval:0.20 repeats:YES block:^(NSTimer * _Nonnull timer) {
__strong typeof(weakSelf) self = weakSelf; if (!self) { [timer invalidate]; return; }
if (!self.streamTextView) { [timer invalidate]; return; }
NSInteger total = (NSInteger)self.streamMockSource.length;
if (self.streamMockCursor >= total) {
//
[self.streamTextView finishStreaming];
[timer invalidate];
self.streamMockTimer = nil;
return;
}
// 1~3
uint32_t step = arc4random_uniform(3) + 1; // 1..3
NSInteger remain = total - self.streamMockCursor;
NSInteger take = MIN((NSInteger)step, remain);
NSString *piece = [self.streamMockSource substringWithRange:NSMakeRange(self.streamMockCursor, take)];
self.streamMockCursor += take;
[self.streamTextView appendStreamText:piece ?: @""];
}];
}
- (void)kb_stopMockStreaming {
[self.streamMockTimer invalidate];
self.streamMockTimer = nil;
self.streamMockChunks = nil;
self.streamMockIndex = 0;
self.streamMockSource = nil;
self.streamMockCursor = 0;
}
#pragma mark - Network Streaming (GET)
// ATS target Info.plist HTTP
static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/talk";
- (void)kb_startNetworkStreamingWithSeed:(NSString *)seedTitle fallbackToMock:(BOOL)fallback {
- (void)kb_startNetworkStreamingWithSeed:(NSString *)seedTitle {
[self kb_stopNetworkStreaming];
if (![[KBFullAccessManager shared] hasFullAccess]) { if (fallback) /*[self kb_startMockStreamingWithSeed:seedTitle]*/; return; }
if (![[KBFullAccessManager shared] hasFullAccess]) { return; }
NSURL *url = [NSURL URLWithString:kKBStreamDemoURL];
if (!url) { if (fallback) [self kb_startMockStreamingWithSeed:seedTitle]; return; }
if (!url) { return; }
self.streamHasOutput = NO; //
__weak typeof(self) weakSelf = self;
@@ -333,9 +282,9 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
};
fetcher.onFinish = ^(NSError * _Nullable error) {
__strong typeof(weakSelf) self = weakSelf; if (!self) return;
if (error && fallback && !self.streamHasOutput) {
[KBHUD showInfo:@"拉取失败,使用本地演示"]; //
[self kb_startMockStreamingWithSeed:nil];
if (error) {
[KBHUD showInfo:@"拉取失败"];
[self.streamTextView finishStreaming];
} else {
[self.streamTextView finishStreaming];
}