Ver Fonte

add a persistent anonymous uinque id.

oldj há 4 anos atrás
pai
commit
56713de272
2 ficheiros alterados com 17 adições e 2 exclusões
  1. 16 1
      src/main/actions/checkUpdate.ts
  2. 1 1
      src/main/types.d.ts

+ 16 - 1
src/main/actions/checkUpdate.ts

@@ -9,12 +9,27 @@ import { GET } from '@main/libs/request'
 import { server_url } from '@root/common/constants'
 import version from '@root/version.json'
 import compareVersions from 'compare-versions'
+import { cfgdb } from '@main/data'
+import { v4 as uuid4 } from 'uuid'
+
+const getUniqueId = async (): Promise<string> => {
+  let uid: string = await cfgdb.dict.local.get('uid', '')
+  if (!uid) {
+    uid = uuid4()
+    await cfgdb.dict.local.set('uid', uid)
+  }
+  return uid
+}
 
 export default async (): Promise<boolean | null> => {
   // Check the latest version, also used for anonymous statistics of DAU,
   // no personal information will be sent.
 
-  let r = await GET(`${server_url}/api/check/`, { sid: global.session_id })
+  let r = await GET(`${server_url}/api/check/`, {
+    sid: global.session_id,
+    uid: await getUniqueId(),
+  })
+
   if (r.status !== 200 || !r.data?.success) {
     return null
   }

+ 1 - 1
src/main/types.d.ts

@@ -4,7 +4,7 @@
  * @homepage: https://oldj.net
  */
 
-import SwhDb from '@main/utils/db'
+import SwhDb from 'potdb'
 import { BrowserWindow } from 'electron'
 import * as actions from './actions'