Skip to content

Commit

Permalink
add IGNORE_DATA_STORE
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed Jul 21, 2023
1 parent 57ad123 commit d05f79e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ REJECT_CALLS=message to send when receive a call, default is empty and not rejec
REJECT_CALLS_WEBHOOK=message to send webook when receive a call, default is empty and not send
SEND_CONNECTION_STATUS=true to send all connection status to webhook, false to send only important messages, default is true
UNOAPI_BASE_STORE=dir where save sessions, medias and stores. Defaul is ./data
IGNORE_DATA_STORE=ignore save/retrieve data(message, contacts, groups...)
```

## Examples
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unoapi-cloud",
"version": "0.28.0",
"version": "0.29.0-dev",
"description": "Unoapi Cloud",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type Config = {
webhooks: Webhook[]
logLevel: string
getGroupMetadata: GetGroupMetadata
ignoreDataStore: boolean
}

export const defaultConfig: Config = {
Expand Down Expand Up @@ -86,6 +87,7 @@ export const defaultConfig: Config = {
},
],
getGroupMetadata: ignoreGetGroupMetadata,
ignoreDataStore: false,
}

export interface getConfig {
Expand Down
2 changes: 2 additions & 0 deletions src/services/config_by_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
WEBHOOK_TOKEN,
WEBHOOK_HEADER,
COMPOSING_MESSAGE,
IGNORE_DATA_STORE,
} = process.env

let config: Config
Expand All @@ -32,6 +33,7 @@ export const getConfigByEnv: getConfig = async (phone: string): Promise<Config>
config.ignoreBroadcastStatuses = IGNORE_BROADCAST_STATUSES === _undefined ? true : IGNORE_BROADCAST_STATUSES == 'true'
config.ignoreBroadcastMessages = IGNORE_BROADCAST_MESSAGES === _undefined ? false : IGNORE_OWN_MESSAGES == 'true'
config.ignoreHistoryMessages = IGNORE_HISTORY_MESSAGES === _undefined ? false : IGNORE_HISTORY_MESSAGES == 'true'
config.ignoreDataStore = IGNORE_DATA_STORE === _undefined ? false : IGNORE_DATA_STORE == 'true'
config.ignoreYourselfMessages = IGNORE_YOURSELF_MESSAGES === _undefined ? false : IGNORE_YOURSELF_MESSAGES == 'true'
config.ignoreOwnMessages = IGNORE_OWN_MESSAGES === _undefined ? true : IGNORE_OWN_MESSAGES == 'true'
config.sendConnectionStatus = SEND_CONNECTION_STATUS === _undefined ? true : SEND_CONNECTION_STATUS == 'true'
Expand Down
18 changes: 10 additions & 8 deletions src/services/store_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ const storeFile: store = async (phone: string, config: Config): Promise<Store> =
rmSync(dataFile)
}
}
try {
dataStore.readFromFile(dataFile)
} catch (error) {
console.debug(`Try read ${dataFile} again....`)
if (!config.ignoreDataStore) {
try {
dataStore.readFromFile(dataFile)
} catch (error) {
console.error(`Error on read data store`, error)
console.debug(`Try read ${dataFile} again....`)
try {
dataStore.readFromFile(dataFile)
} catch (error) {
console.error(`Error on read data store`, error)
}
}
setInterval(() => {
dataStore.writeToFile(dataFile), 10_0000
})
}
setInterval(() => {
dataStore.writeToFile(dataFile), 10_0000
})
return { state, saveCreds, dataStore, mediaStore }
}

0 comments on commit d05f79e

Please sign in to comment.