@kne/fastify-intl-admin 0.1.0
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/README.md +337 -0
- package/index.js +45 -0
- package/libs/controllers/lang-lib.js +165 -0
- package/libs/controllers/lang-type.js +115 -0
- package/libs/models/lang-lib.js +73 -0
- package/libs/models/lang-type.js +67 -0
- package/libs/schema/lang-lib.js +157 -0
- package/libs/schema/lang-type.js +90 -0
- package/libs/services/lang-lib.js +625 -0
- package/libs/services/lang-type.js +381 -0
- package/libs/utils/http-errors.js +48 -0
- package/libs/utils/i18n-file.js +134 -0
- package/libs/utils/list-query.js +58 -0
- package/package.json +66 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module.exports = ({ DataTypes, options }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
4
|
+
namespace: {
|
|
5
|
+
type: DataTypes.STRING,
|
|
6
|
+
allowNull: false,
|
|
7
|
+
comment: '命名空间'
|
|
8
|
+
},
|
|
9
|
+
code: {
|
|
10
|
+
type: DataTypes.STRING,
|
|
11
|
+
allowNull: false,
|
|
12
|
+
comment: '词条编码'
|
|
13
|
+
},
|
|
14
|
+
locale: {
|
|
15
|
+
type: DataTypes.STRING,
|
|
16
|
+
allowNull: false,
|
|
17
|
+
comment: '语言编码'
|
|
18
|
+
},
|
|
19
|
+
target: {
|
|
20
|
+
type: DataTypes.TEXT,
|
|
21
|
+
allowNull: true,
|
|
22
|
+
defaultValue: '',
|
|
23
|
+
comment: '译文'
|
|
24
|
+
},
|
|
25
|
+
reviewStatus: {
|
|
26
|
+
type: DataTypes.ENUM('approved', 'pending', 'rejected'),
|
|
27
|
+
allowNull: false,
|
|
28
|
+
defaultValue: 'pending',
|
|
29
|
+
comment: '审核状态'
|
|
30
|
+
},
|
|
31
|
+
reviewRemark: {
|
|
32
|
+
type: DataTypes.TEXT,
|
|
33
|
+
allowNull: true,
|
|
34
|
+
comment: '审核备注'
|
|
35
|
+
},
|
|
36
|
+
status: {
|
|
37
|
+
type: DataTypes.ENUM('open', 'closed'),
|
|
38
|
+
allowNull: false,
|
|
39
|
+
defaultValue: 'open',
|
|
40
|
+
comment: '状态:open 启用,closed 禁用'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
associate: ({ langLib }) => {
|
|
44
|
+
langLib.belongsTo(options.getUserModel(), {
|
|
45
|
+
foreignKey: 'userId',
|
|
46
|
+
as: 'createdUser',
|
|
47
|
+
comment: '添加人'
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
options: {
|
|
51
|
+
comment: '语言库词条',
|
|
52
|
+
indexes: [
|
|
53
|
+
{
|
|
54
|
+
unique: true,
|
|
55
|
+
fields: ['namespace', 'code', 'locale'],
|
|
56
|
+
where: { deleted_at: null }
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
fields: ['namespace', 'code']
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
fields: ['locale']
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
fields: ['review_status']
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
fields: ['user_id']
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module.exports = ({ DataTypes, options }) => {
|
|
2
|
+
return {
|
|
3
|
+
model: {
|
|
4
|
+
name: {
|
|
5
|
+
type: DataTypes.STRING,
|
|
6
|
+
allowNull: false,
|
|
7
|
+
comment: '语言名称'
|
|
8
|
+
},
|
|
9
|
+
code: {
|
|
10
|
+
type: DataTypes.STRING,
|
|
11
|
+
allowNull: false,
|
|
12
|
+
comment: '语言编码,如 zh-CN'
|
|
13
|
+
},
|
|
14
|
+
params: {
|
|
15
|
+
type: DataTypes.STRING,
|
|
16
|
+
allowNull: true,
|
|
17
|
+
comment: '翻译参数提示'
|
|
18
|
+
},
|
|
19
|
+
description: {
|
|
20
|
+
type: DataTypes.TEXT,
|
|
21
|
+
allowNull: true,
|
|
22
|
+
comment: '描述'
|
|
23
|
+
},
|
|
24
|
+
status: {
|
|
25
|
+
type: DataTypes.ENUM('open', 'closed'),
|
|
26
|
+
allowNull: false,
|
|
27
|
+
defaultValue: 'open',
|
|
28
|
+
comment: '状态:open 启用,closed 禁用'
|
|
29
|
+
},
|
|
30
|
+
isDefault: {
|
|
31
|
+
type: DataTypes.BOOLEAN,
|
|
32
|
+
allowNull: false,
|
|
33
|
+
defaultValue: false,
|
|
34
|
+
comment: '是否为默认语言'
|
|
35
|
+
},
|
|
36
|
+
sort: {
|
|
37
|
+
type: DataTypes.INTEGER,
|
|
38
|
+
allowNull: false,
|
|
39
|
+
defaultValue: 0,
|
|
40
|
+
comment: '排序,越小越靠前'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
associate: ({ langType }) => {
|
|
44
|
+
langType.belongsTo(options.getUserModel(), {
|
|
45
|
+
foreignKey: 'userId',
|
|
46
|
+
as: 'createdUser',
|
|
47
|
+
comment: '添加人'
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
options: {
|
|
51
|
+
comment: '语言类型',
|
|
52
|
+
indexes: [
|
|
53
|
+
{
|
|
54
|
+
unique: true,
|
|
55
|
+
fields: ['code'],
|
|
56
|
+
where: { deleted_at: null }
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
fields: ['user_id']
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
fields: ['sort']
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
const listQuery = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
filter: { type: 'object', default: {} },
|
|
5
|
+
keyword: { type: 'string' },
|
|
6
|
+
namespace: { type: 'string' },
|
|
7
|
+
locale: { type: 'string' },
|
|
8
|
+
reviewStatus: { type: 'string', enum: ['approved', 'pending', 'rejected'] },
|
|
9
|
+
perPage: { type: 'number', default: 20 },
|
|
10
|
+
currentPage: { type: 'number', default: 1 }
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const addPackageBody = {
|
|
15
|
+
type: 'object',
|
|
16
|
+
required: ['namespace', 'code', 'locales'],
|
|
17
|
+
properties: {
|
|
18
|
+
namespace: { type: 'string' },
|
|
19
|
+
code: { type: 'string' },
|
|
20
|
+
locales: {
|
|
21
|
+
type: 'array',
|
|
22
|
+
minItems: 1,
|
|
23
|
+
items: { type: 'string' }
|
|
24
|
+
},
|
|
25
|
+
aiGenerate: { type: 'boolean', default: false },
|
|
26
|
+
sourceTarget: { type: 'string' },
|
|
27
|
+
defaultLocale: { type: 'string' },
|
|
28
|
+
targets: { type: 'object', additionalProperties: { type: 'string' } }
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const saveBody = {
|
|
33
|
+
type: 'object',
|
|
34
|
+
required: ['id'],
|
|
35
|
+
properties: {
|
|
36
|
+
id: {},
|
|
37
|
+
target: { type: 'string' },
|
|
38
|
+
namespace: { type: 'string' },
|
|
39
|
+
code: { type: 'string' },
|
|
40
|
+
locale: {},
|
|
41
|
+
status: { type: 'string', enum: ['open', 'closed'] }
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const removeBody = {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
id: {},
|
|
49
|
+
ids: {
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: {}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const setStatusBody = {
|
|
57
|
+
type: 'object',
|
|
58
|
+
required: ['status'],
|
|
59
|
+
properties: {
|
|
60
|
+
id: {},
|
|
61
|
+
ids: {
|
|
62
|
+
type: 'array',
|
|
63
|
+
items: {}
|
|
64
|
+
},
|
|
65
|
+
status: { type: 'string', enum: ['open', 'closed'] }
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const reviewBody = {
|
|
70
|
+
type: 'object',
|
|
71
|
+
required: ['reviewStatus'],
|
|
72
|
+
properties: {
|
|
73
|
+
id: {},
|
|
74
|
+
ids: {
|
|
75
|
+
type: 'array',
|
|
76
|
+
items: {}
|
|
77
|
+
},
|
|
78
|
+
reviewStatus: { type: 'string', enum: ['approved', 'rejected'] },
|
|
79
|
+
reviewRemark: { type: 'string', maxLength: 500 }
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const regenerateBody = {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
id: {},
|
|
87
|
+
ids: {
|
|
88
|
+
type: 'array',
|
|
89
|
+
items: {}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const copyToNamespaceBody = {
|
|
95
|
+
type: 'object',
|
|
96
|
+
required: ['namespace'],
|
|
97
|
+
properties: {
|
|
98
|
+
namespace: { type: 'string' },
|
|
99
|
+
id: {},
|
|
100
|
+
ids: {
|
|
101
|
+
type: 'array',
|
|
102
|
+
items: {}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const messagesQuery = {
|
|
108
|
+
type: 'object',
|
|
109
|
+
required: ['locale'],
|
|
110
|
+
properties: {
|
|
111
|
+
locale: { type: 'string' },
|
|
112
|
+
namespace: { type: 'string', default: 'global' }
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const exportQuery = {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
namespace: { type: 'string' }
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const importFileItem = {
|
|
124
|
+
type: 'object',
|
|
125
|
+
required: ['filename', 'content'],
|
|
126
|
+
properties: {
|
|
127
|
+
filename: { type: 'string' },
|
|
128
|
+
content: { type: 'string' }
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const importBody = {
|
|
133
|
+
type: 'object',
|
|
134
|
+
properties: {
|
|
135
|
+
filename: { type: 'string' },
|
|
136
|
+
content: { type: 'string' },
|
|
137
|
+
files: {
|
|
138
|
+
type: 'array',
|
|
139
|
+
minItems: 1,
|
|
140
|
+
items: importFileItem
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
module.exports = {
|
|
146
|
+
listQuery,
|
|
147
|
+
addPackageBody,
|
|
148
|
+
saveBody,
|
|
149
|
+
removeBody,
|
|
150
|
+
setStatusBody,
|
|
151
|
+
reviewBody,
|
|
152
|
+
regenerateBody,
|
|
153
|
+
copyToNamespaceBody,
|
|
154
|
+
messagesQuery,
|
|
155
|
+
exportQuery,
|
|
156
|
+
importBody
|
|
157
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const listQuery = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
filter: { type: 'object', default: {} },
|
|
5
|
+
keyword: { type: 'string' },
|
|
6
|
+
namespace: { type: 'string' },
|
|
7
|
+
isDefault: { type: 'boolean' },
|
|
8
|
+
perPage: { type: 'number', default: 20 },
|
|
9
|
+
currentPage: { type: 'number', default: 1 }
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const createBody = {
|
|
14
|
+
type: 'object',
|
|
15
|
+
required: ['name', 'code'],
|
|
16
|
+
properties: {
|
|
17
|
+
name: { type: 'string' },
|
|
18
|
+
code: { type: 'string' },
|
|
19
|
+
params: { type: 'string' },
|
|
20
|
+
description: { type: 'string' },
|
|
21
|
+
status: { type: 'string', enum: ['open', 'closed'] }
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const saveBody = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
required: ['id'],
|
|
28
|
+
properties: {
|
|
29
|
+
id: {},
|
|
30
|
+
name: { type: 'string' },
|
|
31
|
+
params: { type: 'string' },
|
|
32
|
+
description: { type: 'string' },
|
|
33
|
+
status: { type: 'string', enum: ['open', 'closed'] }
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const removeBody = {
|
|
38
|
+
type: 'object',
|
|
39
|
+
required: ['id'],
|
|
40
|
+
properties: {
|
|
41
|
+
id: {}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const setStatusBody = {
|
|
46
|
+
type: 'object',
|
|
47
|
+
required: ['id', 'status'],
|
|
48
|
+
properties: {
|
|
49
|
+
id: {},
|
|
50
|
+
status: { type: 'string', enum: ['open', 'closed'] }
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const setDefaultBody = {
|
|
55
|
+
type: 'object',
|
|
56
|
+
required: ['id'],
|
|
57
|
+
properties: {
|
|
58
|
+
id: {}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const moveBody = {
|
|
63
|
+
type: 'object',
|
|
64
|
+
required: ['id', 'direction'],
|
|
65
|
+
properties: {
|
|
66
|
+
id: {},
|
|
67
|
+
direction: { type: 'string', enum: ['up', 'down'] }
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const translateRemainingBody = {
|
|
72
|
+
type: 'object',
|
|
73
|
+
required: ['id'],
|
|
74
|
+
properties: {
|
|
75
|
+
id: {},
|
|
76
|
+
namespace: { type: 'string' },
|
|
77
|
+
limit: { type: 'integer', minimum: 1, maximum: 500 }
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
listQuery,
|
|
83
|
+
createBody,
|
|
84
|
+
saveBody,
|
|
85
|
+
removeBody,
|
|
86
|
+
setStatusBody,
|
|
87
|
+
setDefaultBody,
|
|
88
|
+
moveBody,
|
|
89
|
+
translateRemainingBody
|
|
90
|
+
};
|