MCPcopy
hub / github.com/InkTimeRecord/TTime / getOcrServiceMap

Function getOcrServiceMap

src/renderer/src/utils/ocrServiceUtil.ts:35–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33 * 获取Ocr服务list
34 */
35export const getOcrServiceMap = (): Map<any, any> => {
36 let map = new Map(cacheGet('ocrServiceMap'))
37 if (map.size > 0) {
38 // 因为之前的版本中的数据没有 index 所以这里默认获取第一条翻译源
39 // 看是否有设置 index 如果没有默认赋值一遍
40 const ocrServiceOne = map.entries().next().value[0]
41 if (isNull(ocrServiceOne['index'])) {
42 setOcrServiceMap(map)
43 }
44 }
45 map = new Map(cacheGet('ocrServiceMap'))
46 // 将 Map 转换为包含键值对数组的二维数组
47 const entries = Array.from(map.entries())
48 // 对二维数组按照对象的 index 属性进行排序
49 entries.sort((a, b) => a[1]['index'] - b[1]['index'])
50 // 创建一个新的有序 Map
51 map = new Map(entries)
52 // 此处设置渠道信息
53 map.forEach((translateService) => {
54 translateService['serviceInfo'] = OcrServiceBuilder.getInfoByService(translateService['type'])
55 })
56 return map
57}
58
59/**
60 * 获取Ocr服务 - 只获取出可使用的

Callers 2

saveServiceInfoHandleFunction · 0.90
getOcrServiceMapByUseFunction · 0.85

Calls 4

cacheGetFunction · 0.90
isNullFunction · 0.90
setOcrServiceMapFunction · 0.85
getInfoByServiceMethod · 0.45

Tested by

no test coverage detected