Skip to content

Commit cd52f3a

Browse files
Added endpoint as option when configuring client
1 parent 3456808 commit cd52f3a

File tree

10 files changed

+284
-3
lines changed

10 files changed

+284
-3
lines changed

src/main-process/common/s3.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ exports.syncObjectsFromS3 = async () => {
3434
const start = new Date();
3535
const client = new S3Client({
3636
region: settings.region,
37+
endpoint: settings.endpoint,
3738
credentials: {
3839
accessKeyId: settings.accessKeyId,
3940
secretAccessKey: settings.secretAccessKey,
4041
},
4142
});
43+
4244
const scanObjects = async continuationToken => {
4345
const pathSet = new Set();
4446
const result = await client.send(new ListObjectsV2Command({
4547
Bucket: settings.bucket,
4648
ContinuationToken: continuationToken,
4749
}));
50+
4851
const convertS3Object = ({Key, Size, LastModified, StorageClass}) => ({
4952
type: Key.slice(-1) === '/' ? OBJECT_TYPE.FOLDER : OBJECT_TYPE.FILE,
5053
path: Key,
@@ -105,6 +108,7 @@ exports.syncObjectsFromS3 = async () => {
105108
exports.headObject = (path, options) => {
106109
const client = new S3Client({
107110
region: settings.region,
111+
endpoint: settings.endpoint,
108112
credentials: {
109113
accessKeyId: settings.accessKeyId,
110114
secretAccessKey: settings.secretAccessKey,
@@ -127,6 +131,7 @@ exports.headObject = (path, options) => {
127131
exports.getSignedUrl = (path, {expiresIn = 24 * 60 * 60} = {}) => {
128132
const client = new S3Client({
129133
region: settings.region,
134+
endpoint: settings.endpoint,
130135
credentials: {
131136
accessKeyId: settings.accessKeyId,
132137
secretAccessKey: settings.secretAccessKey,
@@ -148,6 +153,7 @@ exports.getSignedUrl = (path, {expiresIn = 24 * 60 * 60} = {}) => {
148153
exports.getObject = path => {
149154
const client = new S3Client({
150155
region: settings.region,
156+
endpoint: settings.endpoint,
151157
credentials: {
152158
accessKeyId: settings.accessKeyId,
153159
secretAccessKey: settings.secretAccessKey,
@@ -170,6 +176,7 @@ exports.getObject = path => {
170176
exports.putObject = (path, options = {}) => {
171177
const client = new S3Client({
172178
region: settings.region,
179+
endpoint: settings.endpoint,
173180
credentials: {
174181
accessKeyId: settings.accessKeyId,
175182
secretAccessKey: settings.secretAccessKey,
@@ -195,6 +202,7 @@ exports.putObject = (path, options = {}) => {
195202
exports.upload = ({path, content, options, onProgress}) => {
196203
const client = new S3Client({
197204
region: settings.region,
205+
endpoint: settings.endpoint,
198206
credentials: {
199207
accessKeyId: settings.accessKeyId,
200208
secretAccessKey: settings.secretAccessKey,
@@ -225,6 +233,7 @@ exports.upload = ({path, content, options, onProgress}) => {
225233
exports.deleteObjects = paths => {
226234
const client = new S3Client({
227235
region: settings.region,
236+
endpoint: settings.endpoint,
228237
credentials: {
229238
accessKeyId: settings.accessKeyId,
230239
secretAccessKey: settings.secretAccessKey,

src/main-process/ipc-handlers/main-api/settings-handler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ exports.getSettings = async () => {
2424
* @param {string} bucket
2525
* @returns {Promise<SettingsModel>}
2626
*/
27-
exports.updateS3Settings = async ({accessKeyId, secretAccessKey, region, bucket} = {}) => {
27+
exports.updateS3Settings = async ({accessKeyId, secretAccessKey, region, bucket, endpoint} = {}) => {
2828
await SettingsModel.upsert(
2929
{
3030
id: MAIN_SETTINGS_ID,
3131
accessKeyId,
3232
region,
3333
bucket,
3434
...(secretAccessKey ? {secretAccessKey} : {}),
35+
endpoint,
3536
},
3637
{
3738
updateOnDuplicate: [
3839
'accessKeyId',
3940
'secretAccessKey',
4041
'region',
4142
'bucket',
43+
'endpoint',
4244
'cryptoIv',
4345
'updatedAt',
4446
],
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
const Sequelize = require('sequelize');
4+
5+
/**
6+
* Actions summary:
7+
*
8+
* addColumn "endpoint" to table "settings"
9+
*
10+
**/
11+
12+
const info = {
13+
revision: 2,
14+
name: '$npm_package_version',
15+
created: '2023-09-18T22:42:26.680Z',
16+
comment: '',
17+
};
18+
19+
const migrationCommands = [{
20+
fn: 'addColumn',
21+
params: [
22+
'settings',
23+
'endpoint',
24+
{
25+
type: Sequelize.STRING,
26+
field: 'endpoint',
27+
allowNull: true,
28+
},
29+
],
30+
}];
31+
32+
module.exports = {
33+
pos: 0,
34+
up(queryInterface, Sequelize) {
35+
let index = this.pos;
36+
return new Promise((resolve, reject) => {
37+
function next() {
38+
if (index < migrationCommands.length) {
39+
const command = migrationCommands[index];
40+
console.log('[#' + index + '] execute: ' + command.fn);
41+
index++;
42+
queryInterface[command.fn].apply(queryInterface, command.params).then(next, reject);
43+
} else {
44+
resolve();
45+
}
46+
}
47+
48+
next();
49+
});
50+
},
51+
info,
52+
};

src/main-process/migrations/_current.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@
162162
"field": "bucket",
163163
"seqType": "Sequelize.STRING"
164164
},
165+
"endpoint": {
166+
"allowNull": true,
167+
"field": "endpoint",
168+
"seqType": "Sequelize.STRING"
169+
},
165170
"createdAt": {
166171
"allowNull": false,
167172
"field": "createdAt",
@@ -176,5 +181,5 @@
176181
"indexes": []
177182
}
178183
},
179-
"revision": 1
184+
"revision": 2
180185
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"tables": {
3+
"objects": {
4+
"tableName": "objects",
5+
"schema": {
6+
"id": {
7+
"allowNull": false,
8+
"primaryKey": true,
9+
"autoIncrement": true,
10+
"field": "id",
11+
"seqType": "Sequelize.INTEGER"
12+
},
13+
"type": {
14+
"allowNull": false,
15+
"validate": {
16+
"isIn": [
17+
[
18+
1,
19+
2
20+
]
21+
]
22+
},
23+
"field": "type",
24+
"seqType": "Sequelize.TINYINT"
25+
},
26+
"path": {
27+
"allowNull": false,
28+
"field": "path",
29+
"seqType": "Sequelize.STRING(1024)"
30+
},
31+
"dirname": {
32+
"allowNull": false,
33+
"field": "dirname",
34+
"seqType": "Sequelize.STRING(1024)"
35+
},
36+
"basename": {
37+
"allowNull": false,
38+
"field": "basename",
39+
"seqType": "Sequelize.CITEXT"
40+
},
41+
"lastModified": {
42+
"allowNull": true,
43+
"defaultValue": {
44+
"internal": true,
45+
"value": "Sequelize.NOW"
46+
},
47+
"field": "lastModified",
48+
"seqType": "Sequelize.DATE"
49+
},
50+
"size": {
51+
"allowNull": true,
52+
"defaultValue": {
53+
"value": 0
54+
},
55+
"field": "size",
56+
"seqType": "Sequelize.BIGINT"
57+
},
58+
"storageClass": {
59+
"allowNull": true,
60+
"validate": {
61+
"isIn": [
62+
[
63+
1,
64+
2,
65+
3,
66+
4,
67+
5,
68+
6,
69+
7,
70+
8,
71+
9
72+
]
73+
]
74+
},
75+
"field": "storageClass",
76+
"seqType": "Sequelize.TINYINT"
77+
},
78+
"createdAt": {
79+
"allowNull": false,
80+
"field": "createdAt",
81+
"seqType": "Sequelize.DATE"
82+
},
83+
"updatedAt": {
84+
"allowNull": false,
85+
"field": "updatedAt",
86+
"seqType": "Sequelize.DATE"
87+
}
88+
},
89+
"indexes": {
90+
"183f280b8914e4555e01bc7ea2b5a6d53968a206": {
91+
"unique": true,
92+
"fields": [
93+
"path"
94+
],
95+
"name": "objects_path",
96+
"options": {
97+
"indexName": "objects_path",
98+
"name": "objects_path",
99+
"indicesType": "UNIQUE",
100+
"type": "UNIQUE"
101+
}
102+
},
103+
"3ec0abbcc3a1c6da61ddba1070d200bc91de5e23": {
104+
"unique": false,
105+
"fields": [
106+
"updatedAt"
107+
],
108+
"name": "objects_updated_at",
109+
"options": {
110+
"indexName": "objects_updated_at",
111+
"name": "objects_updated_at"
112+
}
113+
},
114+
"bfeb9da4c77d8c67376eb7071c7003b1bc16f46e": {
115+
"unique": false,
116+
"fields": [
117+
"dirname",
118+
"type",
119+
"basename",
120+
"id"
121+
],
122+
"name": "objects_dirname_type_basename_id",
123+
"options": {
124+
"indexName": "objects_dirname_type_basename_id",
125+
"name": "objects_dirname_type_basename_id"
126+
}
127+
}
128+
}
129+
},
130+
"settings": {
131+
"tableName": "settings",
132+
"schema": {
133+
"id": {
134+
"allowNull": false,
135+
"primaryKey": true,
136+
"autoIncrement": true,
137+
"field": "id",
138+
"seqType": "Sequelize.INTEGER"
139+
},
140+
"cryptoIv": {
141+
"allowNull": true,
142+
"field": "cryptoIv",
143+
"seqType": "Sequelize.STRING"
144+
},
145+
"accessKeyId": {
146+
"allowNull": true,
147+
"field": "accessKeyId",
148+
"seqType": "Sequelize.STRING"
149+
},
150+
"secretAccessKey": {
151+
"allowNull": true,
152+
"field": "secretAccessKey",
153+
"seqType": "Sequelize.STRING"
154+
},
155+
"region": {
156+
"allowNull": true,
157+
"field": "region",
158+
"seqType": "Sequelize.STRING"
159+
},
160+
"bucket": {
161+
"allowNull": true,
162+
"field": "bucket",
163+
"seqType": "Sequelize.STRING"
164+
},
165+
"createdAt": {
166+
"allowNull": false,
167+
"field": "createdAt",
168+
"seqType": "Sequelize.DATE"
169+
},
170+
"updatedAt": {
171+
"allowNull": false,
172+
"field": "updatedAt",
173+
"seqType": "Sequelize.DATE"
174+
}
175+
},
176+
"indexes": []
177+
}
178+
},
179+
"revision": 1
180+
}

src/main-process/models/data/settings-model.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const attributes = {
4747
type: DataTypes.STRING,
4848
allowNull: true,
4949
},
50+
endpoint: {
51+
type: DataTypes.STRING,
52+
allowNull: true,
53+
},
5054
};
5155
const options = {
5256
indexes: [],

src/main-process/preload/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ exports.api = {
118118
return sendApiRequest({method: 'getSettings'});
119119
},
120120
/**
121-
* @param {{accessKeyId: string, secretAccessKey: string, region: string, bucket: string}} data
121+
* @param {{accessKeyId: string, secretAccessKey: string, region: string, bucket: string, endpoint: string}} data
122122
* @returns {Promise<{id, accessKeyId, bucket, region, updatedAt, createdAt}>}
123123
*/
124124
updateS3Settings(data) {

0 commit comments

Comments
 (0)