netease-im / nim-harmony-demo

云信IMSDK,鸿蒙使用Demo
MIT License
23 stars 2 forks source link

1.1.0-beta 崩溃 #6

Closed trhyl closed 1 month ago

trhyl commented 1 month ago

Device info:HUAWEI Mate 60 Pro Build info:ALN-AL00 5.0.0.26(SP8DEVC00E29R4P6log) Fingerprint:5be5f3a847139b6524c99cc6ac1088f5d893556f9909651824b6279f6eb028f5 Module name:com.zhilian.myapplication Version:1.0.0 VersionCode:1000000 PreInstalled:No Foreground:No Pid:41781 Uid:20020008 Reason:SyntaxError Error name:SyntaxError Error message:Unexpected end Text in JSON SourceCode: import fs from '@ohos:file.fs'; import Hash from '@ohos:file.hash'; import util from '@ohos:util'; export class AntispamModel { constructor(a2) { this.thesaurus = []; this.antispamKey = 'NIM_Antispam_Key'; this.core = a2; this.loadLocalAntispam(); } async getVersion() { return new Promise(async (t1, u1) => { let v1 = await this.core.kvManager.getKVStore(this.core.account); v1.get(this.antispamKey).then((data) => { console.info(Succeeded in getting data.data=${data}); const version = data; t1(version); }).catch((err) => { if (err.code == 15100004) { t1('0'); } else { u1(err); this.core.logger.error(getVersion: ${err}); } }); }); } async setVersion(version) { let q1 = await this.core.kvManager.getKVStore(this.core.account); await q1.put(this.antispamKey, version); } loadLocalAntispam() { try { const filePath = this.getLocalAntispamPath(); const file = fs.openSync(filePath, fs.OpenMode.READ_WRITE); const arrayBuffer = new ArrayBuffer(4096); fs.read(file.fd, arrayBuffer, (err, p1) => { if (!err) { this.thes aurus = this.decode(arrayBuffer); } fs.closeSync(file); }); } catch (e) { this.core.logger.error(loadLocalAntispam: ${e}); } } async updateLocalAntispam(version, result) { if (typeof result.data !== 'string') { this.thesaurus = this.decode(result.data); } else { this.thesaurus = JSON.parse(result.data); } await this.writeFile(result.data); await this.setVersion(version); } async writeFile(data) { try { const filePath = this.getLocalAntispamPath(); const file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); await fs.write(file.fd, data); await fs.close(file); } catch (e) { this.core.logger.error(antispam writeFile failed ${e}}); } } checkMd5(l1, callback) { const filePath = this.getLocalAntispamPath(); Hash.hash(filePath, 'md5').then((str) => { this.core.logger.info(antispam md5: ${l1} str : ${str}); if (l1 !== str) { callback(true); } else { callback(false); } }).catch((err) => { this.core.logger.error('calculate file hash failed' + err.message + ', error code: ' + err.code); call back(true); }); } getLocalAntispamPath() { const k1 = this.core.context.cacheDir + '/nim_sdk'; if (!fs.accessSync(k1)) { fs.mkdirSync(k1); } const filePath = k1 + /v2_antispam_cache.info; return filePath; } decode(data) { const h1 = new Uint8Array(data); const i1 = util.TextDecoder.create('utf-8', { fatal: false, ignoreBOM: true }); const j1 = i1.decodeWithStream(h1, { stream: false }); const all = JSON.parse(j1); return all.thesaurus; } }

                                                                                                                                                                                                                                                                                                                                                                                                                ^

Stacktrace: Cannot get SourceMap info, dump raw stack: at decode (entry|@nimsdk/message|1.1.0-beta|src/main/ets/services/antispam/AntispamModel.js:1:2449) at anonymous (entry|@nimsdk/message|1.1.0-beta|src/main/ets/services/antispam/AntispamModel.js:1:1031)

hongru1227 commented 1 month ago

这个是已知问题,下个版本修复