// // Untitled.swift // Crush // // Created by Leon on 2025/7/29. // extension Data { static func okContent(string: String) -> Data { guard let contentData = string.data(using: .utf8), let contentObject = try? JSONSerialization.jsonObject(with: contentData) else { return Data() } let wrapper: [String: Any] = [ "content": contentObject, "status": "OK", "errorCode": "", "errorMsg": "", "traceId": "", ] return (try? JSONSerialization.data(withJSONObject: wrapper)) ?? Data() } static func okData() -> Data { let mockJSON = """ { "content": null, "status": "OK", "errorCode": "", "errorMsg": "", "traceId": "" } """ return Data(mockJSON.utf8) } static func okPageDatas(string: String)->Data{ guard let contentData = string.data(using: .utf8), let contentObject = try? JSONSerialization.jsonObject(with: contentData) else { return Data() } let wrapper: [String: Any] = [ "content": [ "pn": 0, "ps": 0, "datas":contentObject, "tc": 0, "sortType": "", "sortField": "" ], "status": "OK", "errorCode": "", "errorMsg": "", "traceId": "" ] return (try? JSONSerialization.data(withJSONObject: wrapper)) ?? Data() } static func aiMockInfo() -> Data{ let mockJSON = """ { "aiId": 101, "nickname": "MockAI-001", "sex": 1, "headImg": "https://example.com/avatar.jpg", "birthday": "1999-12-31", "roleCode": "mentor", "role": "Mentor", "characterCode": "kind", "character": "Kind", "tagCode": "funny", "tag": "Funny", "introduction": "I am a helpful and friendly AI created to assist you.", "permission": 1, "imageUrl": "https://fastly.picsum.photos/id/866/200/300.jpg?hmac=rcadCENKh4rD6MAp6V_ma-AyWv641M4iiOpe1RyFHeI", "aiUserExt": { "profile": "This is a detailed profile of the mock AI.", "dialogueStyle": "Friendly", "dialoguePrologue": "Hi there! I'm ready to help.", "dialogueTimbre": "Warm and clear", "imageStyleCode": "realistic", "imageStyle": "Realistic Illustration", "imageStyleUrl": "https://fastly.picsum.photos/id/888/200/200.jpg?hmac=k4DxIkJ_O8YKi3TA5I9xxJYJzqpSvx3QmJlgZwHMojo", "imageDesc": "An elegant futuristic AI with soft colors", "imageReferenceUrl": "https://picsum.photos/200" } } """ return okContent(string: mockJSON) } }