@dongdev/fca-unofficial 3.0.20 → 3.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/module/loginHelper.js +15 -1
- package/package.json +1 -1
- package/src/database/models/index.js +79 -41
- package/src/database/models/thread.js +16 -2
- package/src/database/models/user.js +16 -2
package/CHANGELOG.md
CHANGED
package/module/loginHelper.js
CHANGED
|
@@ -1005,7 +1005,21 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
|
|
|
1005
1005
|
skipped++;
|
|
1006
1006
|
return;
|
|
1007
1007
|
}
|
|
1008
|
-
|
|
1008
|
+
let mod;
|
|
1009
|
+
try {
|
|
1010
|
+
mod = require(p);
|
|
1011
|
+
} catch (e) {
|
|
1012
|
+
logger(`Failed to require API module ${p}: ${e && e.message ? e.message : String(e)}`, "warn");
|
|
1013
|
+
skipped++;
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
const factory = typeof mod === "function" ? mod : (mod && typeof mod.default === "function" ? mod.default : null);
|
|
1017
|
+
if (!factory) {
|
|
1018
|
+
logger(`API module ${p} does not export a function, skipping`, "warn");
|
|
1019
|
+
skipped++;
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
api[key] = factory(defaultFuncs, api, ctxMain);
|
|
1009
1023
|
loaded++;
|
|
1010
1024
|
});
|
|
1011
1025
|
});
|
package/package.json
CHANGED
|
@@ -1,49 +1,87 @@
|
|
|
1
1
|
const { Sequelize } = require("sequelize");
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const path = require("path");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
pool: {
|
|
13
|
-
max: 5,
|
|
14
|
-
min: 0,
|
|
15
|
-
acquire: 30000,
|
|
16
|
-
idle: 10000
|
|
17
|
-
},
|
|
18
|
-
retry: {
|
|
19
|
-
max: 3
|
|
20
|
-
},
|
|
21
|
-
dialectOptions: {
|
|
22
|
-
timeout: 5000
|
|
23
|
-
},
|
|
24
|
-
isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
|
|
25
|
-
});
|
|
26
|
-
const models = {};
|
|
27
|
-
fs.readdirSync(__dirname)
|
|
28
|
-
.filter(file => file.endsWith(".js") && file !== "index.js")
|
|
29
|
-
.forEach(file => {
|
|
30
|
-
const model = require(path.join(__dirname, file))(sequelize);
|
|
31
|
-
models[model.name] = model;
|
|
32
|
-
});
|
|
33
|
-
Object.keys(models).forEach(modelName => {
|
|
34
|
-
if (models[modelName].associate) {
|
|
35
|
-
models[modelName].associate(models);
|
|
4
|
+
|
|
5
|
+
let sequelize = null;
|
|
6
|
+
let models = {};
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
const databasePath = path.join(process.cwd(), "Fca_Database");
|
|
10
|
+
if (!fs.existsSync(databasePath)) {
|
|
11
|
+
fs.mkdirSync(databasePath, { recursive: true });
|
|
36
12
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
13
|
+
|
|
14
|
+
sequelize = new Sequelize({
|
|
15
|
+
dialect: "sqlite",
|
|
16
|
+
storage: path.join(databasePath, "database.sqlite"),
|
|
17
|
+
logging: false,
|
|
18
|
+
pool: {
|
|
19
|
+
max: 5,
|
|
20
|
+
min: 0,
|
|
21
|
+
acquire: 30000,
|
|
22
|
+
idle: 10000
|
|
23
|
+
},
|
|
24
|
+
retry: {
|
|
25
|
+
max: 3
|
|
26
|
+
},
|
|
27
|
+
dialectOptions: {
|
|
28
|
+
timeout: 5000
|
|
29
|
+
},
|
|
30
|
+
isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.READ_COMMITTED
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Load models with error handling
|
|
41
34
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
const modelFiles = fs.readdirSync(__dirname)
|
|
36
|
+
.filter(file => file.endsWith(".js") && file !== "index.js");
|
|
37
|
+
|
|
38
|
+
for (const file of modelFiles) {
|
|
39
|
+
try {
|
|
40
|
+
const model = require(path.join(__dirname, file))(sequelize);
|
|
41
|
+
if (model && model.name) {
|
|
42
|
+
models[model.name] = model;
|
|
43
|
+
}
|
|
44
|
+
} catch (modelError) {
|
|
45
|
+
// Log but continue loading other models
|
|
46
|
+
console.error(`Failed to load model ${file}:`, modelError && modelError.message ? modelError.message : String(modelError));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Associate models
|
|
51
|
+
Object.keys(models).forEach(modelName => {
|
|
52
|
+
try {
|
|
53
|
+
if (models[modelName].associate) {
|
|
54
|
+
models[modelName].associate(models);
|
|
55
|
+
}
|
|
56
|
+
} catch (assocError) {
|
|
57
|
+
console.error(`Failed to associate model ${modelName}:`, assocError && assocError.message ? assocError.message : String(assocError));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
} catch (loadError) {
|
|
61
|
+
console.error("Failed to load models:", loadError && loadError.message ? loadError.message : String(loadError));
|
|
46
62
|
}
|
|
47
|
-
|
|
63
|
+
|
|
64
|
+
models.sequelize = sequelize;
|
|
65
|
+
models.Sequelize = Sequelize;
|
|
66
|
+
models.syncAll = async () => {
|
|
67
|
+
try {
|
|
68
|
+
if (!sequelize) {
|
|
69
|
+
throw new Error("Sequelize instance not initialized");
|
|
70
|
+
}
|
|
71
|
+
await sequelize.sync({ force: false });
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error("Failed to synchronize models:", error && error.message ? error.message : String(error));
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
} catch (initError) {
|
|
78
|
+
// If initialization fails completely, still export a valid structure
|
|
79
|
+
console.error("Database initialization error:", initError && initError.message ? initError.message : String(initError));
|
|
80
|
+
models.sequelize = null;
|
|
81
|
+
models.Sequelize = Sequelize;
|
|
82
|
+
models.syncAll = async () => {
|
|
83
|
+
throw new Error("Database not initialized");
|
|
84
|
+
};
|
|
85
|
+
}
|
|
48
86
|
|
|
49
87
|
module.exports = models;
|
|
@@ -17,8 +17,22 @@ module.exports = function(sequelize) {
|
|
|
17
17
|
unique: true
|
|
18
18
|
},
|
|
19
19
|
data: {
|
|
20
|
-
type: DataTypes.
|
|
21
|
-
allowNull: true
|
|
20
|
+
type: DataTypes.TEXT,
|
|
21
|
+
allowNull: true,
|
|
22
|
+
get() {
|
|
23
|
+
const value = this.getDataValue('data');
|
|
24
|
+
if (typeof value === 'string') {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(value);
|
|
27
|
+
} catch {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
},
|
|
33
|
+
set(value) {
|
|
34
|
+
this.setDataValue('data', typeof value === 'string' ? value : JSON.stringify(value));
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
},
|
|
24
38
|
{
|
|
@@ -17,8 +17,22 @@ module.exports = function (sequelize) {
|
|
|
17
17
|
unique: true
|
|
18
18
|
},
|
|
19
19
|
data: {
|
|
20
|
-
type: DataTypes.
|
|
21
|
-
allowNull: true
|
|
20
|
+
type: DataTypes.TEXT,
|
|
21
|
+
allowNull: true,
|
|
22
|
+
get() {
|
|
23
|
+
const value = this.getDataValue('data');
|
|
24
|
+
if (typeof value === 'string') {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(value);
|
|
27
|
+
} catch {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
},
|
|
33
|
+
set(value) {
|
|
34
|
+
this.setDataValue('data', typeof value === 'string' ? value : JSON.stringify(value));
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
},
|
|
24
38
|
{
|