decap-cms-backend-gitea 3.0.4

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 ADDED
@@ -0,0 +1,22 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 3.0.4 (2023-10-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * **backend:** add gitea backend ([#6808](https://github.com/decaporg/decap-cms/issues/6808)) ([0d89a58](https://github.com/decaporg/decap-cms/commit/0d89a58e93f64f868ff3e4e8f0945ccf166ad738))
12
+
13
+
14
+
15
+
16
+
17
+ ## 3.0.3 (2023-10-20)
18
+
19
+
20
+ ### Features
21
+
22
+ * **backend:** add gitea backend ([#6808](https://github.com/decaporg/decap-cms/issues/6808)) ([0d89a58](https://github.com/decaporg/decap-cms/commit/0d89a58e93f64f868ff3e4e8f0945ccf166ad738))
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Netlify <decap@p-m.si>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DecapCmsBackendGitea",[],t):"object"==typeof exports?exports.DecapCmsBackendGitea=t():e.DecapCmsBackendGitea=t()}(window,(()=>(()=>{"use strict";var e={};return e.DecapCmsBackendGitea})()));
2
+ //# sourceMappingURL=decap-cms-backend-gitea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decap-cms-backend-gitea.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,uBAAwB,GAAIH,GACT,iBAAZC,QACdA,QAA8B,qBAAID,IAElCD,EAA2B,qBAAIC,GAChC,CATD,CASGK,QAAQ,I","sources":["webpack://DecapCmsBackendGitea/webpack/universalModuleDefinition"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"DecapCmsBackendGitea\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"DecapCmsBackendGitea\"] = factory();\n\telse\n\t\troot[\"DecapCmsBackendGitea\"] = factory();\n})(window, () => {\nreturn "],"names":["root","factory","exports","module","define","amd","window"],"sourceRoot":""}
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.API_NAME = void 0;
7
+ var _initial2 = _interopRequireDefault(require("lodash/initial"));
8
+ var _last2 = _interopRequireDefault(require("lodash/last"));
9
+ var _partial2 = _interopRequireDefault(require("lodash/partial"));
10
+ var _result2 = _interopRequireDefault(require("lodash/result"));
11
+ var _trim2 = _interopRequireDefault(require("lodash/trim"));
12
+ var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
13
+ var _jsBase = require("js-base64");
14
+ var _decapCmsLibUtil = require("decap-cms-lib-util");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
20
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
+ const API_NAME = exports.API_NAME = 'Gitea';
22
+ var FileOperation = /*#__PURE__*/function (FileOperation) {
23
+ FileOperation["CREATE"] = "create";
24
+ FileOperation["DELETE"] = "delete";
25
+ FileOperation["UPDATE"] = "update";
26
+ return FileOperation;
27
+ }(FileOperation || {});
28
+ class API {
29
+ constructor(config) {
30
+ _defineProperty(this, "apiRoot", void 0);
31
+ _defineProperty(this, "token", void 0);
32
+ _defineProperty(this, "branch", void 0);
33
+ _defineProperty(this, "repo", void 0);
34
+ _defineProperty(this, "originRepo", void 0);
35
+ _defineProperty(this, "repoOwner", void 0);
36
+ _defineProperty(this, "repoName", void 0);
37
+ _defineProperty(this, "originRepoOwner", void 0);
38
+ _defineProperty(this, "originRepoName", void 0);
39
+ _defineProperty(this, "repoURL", void 0);
40
+ _defineProperty(this, "originRepoURL", void 0);
41
+ _defineProperty(this, "_userPromise", void 0);
42
+ _defineProperty(this, "_metadataSemaphore", void 0);
43
+ _defineProperty(this, "commitAuthor", void 0);
44
+ this.apiRoot = config.apiRoot || 'https://try.gitea.io/api/v1';
45
+ this.token = config.token || '';
46
+ this.branch = config.branch || 'master';
47
+ this.repo = config.repo || '';
48
+ this.originRepo = config.originRepo || this.repo;
49
+ this.repoURL = `/repos/${this.repo}`;
50
+ this.originRepoURL = `/repos/${this.originRepo}`;
51
+ const [repoParts, originRepoParts] = [this.repo.split('/'), this.originRepo.split('/')];
52
+ this.repoOwner = repoParts[0];
53
+ this.repoName = repoParts[1];
54
+ this.originRepoOwner = originRepoParts[0];
55
+ this.originRepoName = originRepoParts[1];
56
+ }
57
+ user() {
58
+ if (!this._userPromise) {
59
+ this._userPromise = this.getUser();
60
+ }
61
+ return this._userPromise;
62
+ }
63
+ getUser() {
64
+ return this.request('/user');
65
+ }
66
+ async hasWriteAccess() {
67
+ try {
68
+ const result = await this.request(this.repoURL);
69
+ // update config repoOwner to avoid case sensitivity issues with Gitea
70
+ this.repoOwner = result.owner.login;
71
+ return result.permissions.push;
72
+ } catch (error) {
73
+ console.error('Problem fetching repo data from Gitea');
74
+ throw error;
75
+ }
76
+ }
77
+ reset() {
78
+ // no op
79
+ }
80
+ requestHeaders(headers = {}) {
81
+ const baseHeader = _objectSpread({
82
+ 'Content-Type': 'application/json; charset=utf-8'
83
+ }, headers);
84
+ if (this.token) {
85
+ baseHeader.Authorization = `token ${this.token}`;
86
+ return Promise.resolve(baseHeader);
87
+ }
88
+ return Promise.resolve(baseHeader);
89
+ }
90
+ async parseJsonResponse(response) {
91
+ const json = await response.json();
92
+ if (!response.ok) {
93
+ return Promise.reject(json);
94
+ }
95
+ return json;
96
+ }
97
+ urlFor(path, options) {
98
+ const params = [];
99
+ if (options.params) {
100
+ for (const key in options.params) {
101
+ params.push(`${key}=${encodeURIComponent(options.params[key])}`);
102
+ }
103
+ }
104
+ if (params.length) {
105
+ path += `?${params.join('&')}`;
106
+ }
107
+ return this.apiRoot + path;
108
+ }
109
+ parseResponse(response) {
110
+ const contentType = response.headers.get('Content-Type');
111
+ if (contentType && contentType.match(/json/)) {
112
+ return this.parseJsonResponse(response);
113
+ }
114
+ const textPromise = response.text().then(text => {
115
+ if (!response.ok) {
116
+ return Promise.reject(text);
117
+ }
118
+ return text;
119
+ });
120
+ return textPromise;
121
+ }
122
+ handleRequestError(error, responseStatus) {
123
+ throw new _decapCmsLibUtil.APIError(error.message, responseStatus, API_NAME);
124
+ }
125
+ buildRequest(req) {
126
+ return req;
127
+ }
128
+ async request(path, options = {}, parser = response => this.parseResponse(response)) {
129
+ options = _objectSpread({
130
+ cache: 'no-cache'
131
+ }, options);
132
+ const headers = await this.requestHeaders(options.headers || {});
133
+ const url = this.urlFor(path, options);
134
+ let responseStatus = 500;
135
+ try {
136
+ const req = _decapCmsLibUtil.unsentRequest.fromFetchArguments(url, _objectSpread(_objectSpread({}, options), {}, {
137
+ headers
138
+ }));
139
+ const response = await (0, _decapCmsLibUtil.requestWithBackoff)(this, req);
140
+ responseStatus = response.status;
141
+ const parsedResponse = await parser(response);
142
+ return parsedResponse;
143
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
+ } catch (error) {
145
+ return this.handleRequestError(error, responseStatus);
146
+ }
147
+ }
148
+ nextUrlProcessor() {
149
+ return url => url;
150
+ }
151
+ async requestAllPages(url, options = {}) {
152
+ options = _objectSpread({
153
+ cache: 'no-cache'
154
+ }, options);
155
+ const headers = await this.requestHeaders(options.headers || {});
156
+ const processedURL = this.urlFor(url, options);
157
+ const allResponses = await (0, _decapCmsLibUtil.getAllResponses)(processedURL, _objectSpread(_objectSpread({}, options), {}, {
158
+ headers
159
+ }), 'next', this.nextUrlProcessor());
160
+ const pages = await Promise.all(allResponses.map(res => this.parseResponse(res)));
161
+ return [].concat(...pages);
162
+ }
163
+ generateContentKey(collectionName, slug) {
164
+ return (0, _decapCmsLibUtil.generateContentKey)(collectionName, slug);
165
+ }
166
+ parseContentKey(contentKey) {
167
+ return (0, _decapCmsLibUtil.parseContentKey)(contentKey);
168
+ }
169
+ async readFile(path, sha, {
170
+ branch = this.branch,
171
+ repoURL = this.repoURL,
172
+ parseText = true
173
+ } = {}) {
174
+ if (!sha) {
175
+ sha = await this.getFileSha(path, {
176
+ repoURL,
177
+ branch
178
+ });
179
+ }
180
+ const content = await this.fetchBlobContent({
181
+ sha: sha,
182
+ repoURL,
183
+ parseText
184
+ });
185
+ return content;
186
+ }
187
+ async readFileMetadata(path, sha) {
188
+ const fetchFileMetadata = async () => {
189
+ try {
190
+ const result = await this.request(`${this.originRepoURL}/commits`, {
191
+ params: {
192
+ path,
193
+ sha: this.branch,
194
+ stat: 'false'
195
+ }
196
+ });
197
+ const {
198
+ commit
199
+ } = result[0];
200
+ return {
201
+ author: commit.author.name || commit.author.email,
202
+ updatedOn: commit.author.date
203
+ };
204
+ } catch (e) {
205
+ return {
206
+ author: '',
207
+ updatedOn: ''
208
+ };
209
+ }
210
+ };
211
+ const fileMetadata = await (0, _decapCmsLibUtil.readFileMetadata)(sha, fetchFileMetadata, _decapCmsLibUtil.localForage);
212
+ return fileMetadata;
213
+ }
214
+ async fetchBlobContent({
215
+ sha,
216
+ repoURL,
217
+ parseText
218
+ }) {
219
+ const result = await this.request(`${repoURL}/git/blobs/${sha}`, {
220
+ cache: 'force-cache'
221
+ });
222
+ if (parseText) {
223
+ // treat content as a utf-8 string
224
+ const content = _jsBase.Base64.decode(result.content);
225
+ return content;
226
+ } else {
227
+ // treat content as binary and convert to blob
228
+ const content = _jsBase.Base64.atob(result.content);
229
+ const byteArray = new Uint8Array(content.length);
230
+ for (let i = 0; i < content.length; i++) {
231
+ byteArray[i] = content.charCodeAt(i);
232
+ }
233
+ const blob = new Blob([byteArray]);
234
+ return blob;
235
+ }
236
+ }
237
+ async listFiles(path, {
238
+ repoURL = this.repoURL,
239
+ branch = this.branch,
240
+ depth = 1
241
+ } = {}, folderSupport) {
242
+ const folder = (0, _trim2.default)(path, '/');
243
+ try {
244
+ const result = await this.request(`${repoURL}/git/trees/${branch}:${encodeURIComponent(folder)}`, {
245
+ // Gitea API supports recursive=1 for getting the entire recursive tree
246
+ // or omitting it to get the non-recursive tree
247
+ params: depth > 1 ? {
248
+ recursive: 1
249
+ } : {}
250
+ });
251
+ return result.tree
252
+ // filter only files and/or folders up to the required depth
253
+ .filter(file => (!folderSupport ? file.type === 'blob' : true) && decodeURIComponent(file.path).split('/').length <= depth).map(file => ({
254
+ type: file.type,
255
+ id: file.sha,
256
+ name: (0, _decapCmsLibUtil.basename)(file.path),
257
+ path: `${folder}/${file.path}`,
258
+ size: file.size
259
+ }));
260
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
261
+ } catch (err) {
262
+ if (err && err.status === 404) {
263
+ console.info('[StaticCMS] This 404 was expected and handled appropriately.');
264
+ return [];
265
+ } else {
266
+ throw err;
267
+ }
268
+ }
269
+ }
270
+ async persistFiles(dataFiles, mediaFiles, options) {
271
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
272
+ const files = mediaFiles.concat(dataFiles);
273
+ const operations = await this.getChangeFileOperations(files, this.branch);
274
+ return this.changeFiles(operations, options);
275
+ }
276
+ async changeFiles(operations, options) {
277
+ return await this.request(`${this.repoURL}/contents`, {
278
+ method: 'POST',
279
+ body: JSON.stringify({
280
+ branch: this.branch,
281
+ files: operations,
282
+ message: options.commitMessage
283
+ })
284
+ });
285
+ }
286
+ async getChangeFileOperations(files, branch) {
287
+ const items = await Promise.all(files.map(async file => {
288
+ const content = await (0, _result2.default)(file, 'toBase64', (0, _partial2.default)(this.toBase64, file.raw));
289
+ let sha;
290
+ let operation;
291
+ let from_path;
292
+ let path = (0, _trimStart2.default)(file.path, '/');
293
+ try {
294
+ sha = await this.getFileSha(file.path, {
295
+ branch
296
+ });
297
+ operation = FileOperation.UPDATE;
298
+ from_path = file.newPath && path;
299
+ path = file.newPath ? (0, _trimStart2.default)(file.newPath, '/') : path;
300
+ } catch {
301
+ sha = undefined;
302
+ operation = FileOperation.CREATE;
303
+ }
304
+ return {
305
+ operation,
306
+ content,
307
+ path,
308
+ from_path,
309
+ sha
310
+ };
311
+ }));
312
+ return items;
313
+ }
314
+ async getFileSha(path, {
315
+ repoURL = this.repoURL,
316
+ branch = this.branch
317
+ } = {}) {
318
+ /**
319
+ * We need to request the tree first to get the SHA. We use extended SHA-1
320
+ * syntax (<rev>:<path>) to get a blob from a tree without having to recurse
321
+ * through the tree.
322
+ */
323
+
324
+ const pathArray = path.split('/');
325
+ const filename = (0, _last2.default)(pathArray);
326
+ const directory = (0, _initial2.default)(pathArray).join('/');
327
+ const fileDataPath = encodeURIComponent(directory);
328
+ const fileDataURL = `${repoURL}/git/trees/${branch}:${fileDataPath}`;
329
+ const result = await this.request(fileDataURL);
330
+ const file = result.tree.find(file => file.path === filename);
331
+ if (file) {
332
+ return file.sha;
333
+ } else {
334
+ throw new _decapCmsLibUtil.APIError('Not Found', 404, API_NAME);
335
+ }
336
+ }
337
+ async deleteFiles(paths, message) {
338
+ const operations = await Promise.all(paths.map(async path => {
339
+ const sha = await this.getFileSha(path);
340
+ return {
341
+ operation: FileOperation.DELETE,
342
+ path,
343
+ sha
344
+ };
345
+ }));
346
+ this.changeFiles(operations, {
347
+ commitMessage: message
348
+ });
349
+ }
350
+ toBase64(str) {
351
+ return Promise.resolve(_jsBase.Base64.encode(str));
352
+ }
353
+ }
354
+ exports.default = API;
355
+ _defineProperty(API, "DEFAULT_COMMIT_MESSAGE", 'Automatically generated by Static CMS');
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _base = _interopRequireDefault(require("@emotion/styled/base"));
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _decapCmsLibAuth = require("decap-cms-lib-auth");
11
+ var _decapCmsUiDefault = require("decap-cms-ui-default");
12
+ var _react2 = require("@emotion/react");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
18
+ const LoginButtonIcon = /*#__PURE__*/(0, _base.default)(_decapCmsUiDefault.Icon, {
19
+ target: "es1j68m0",
20
+ label: "LoginButtonIcon"
21
+ })(process.env.NODE_ENV === "production" ? {
22
+ name: "1gnqu05",
23
+ styles: "margin-right:18px"
24
+ } : {
25
+ name: "1gnqu05",
26
+ styles: "margin-right:18px",
27
+ map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9BdXRoZW50aWNhdGlvblBhZ2UuanMiX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XG4gICAgICAgIG9uTG9naW49e3RoaXMuaGFuZGxlTG9naW59XG4gICAgICAgIGxvZ2luRGlzYWJsZWQ9e2luUHJvZ3Jlc3N9XG4gICAgICAgIGxvZ2luRXJyb3JNZXNzYWdlPXt0aGlzLnN0YXRlLmxvZ2luRXJyb3J9XG4gICAgICAgIGxvZ29Vcmw9e2NvbmZpZy5sb2dvVXJsfVxuICAgICAgICBzaXRlVXJsPXtjb25maWcuc2l0ZVVybH1cbiAgICAgICAgcmVuZGVyQnV0dG9uQ29udGVudD17KCkgPT4gKFxuICAgICAgICAgIDxSZWFjdC5GcmFnbWVudD5cbiAgICAgICAgICAgIDxMb2dpbkJ1dHRvbkljb24gdHlwZT1cImdpdGVhXCIgLz57JyAnfVxuICAgICAgICAgICAge2luUHJvZ3Jlc3MgPyB0KCdhdXRoLmxvZ2dpbmdJbicpIDogdCgnYXV0aC5sb2dpbldpdGhHaXRlYScpfVxuICAgICAgICAgIDwvUmVhY3QuRnJhZ21lbnQ+XG4gICAgICAgICl9XG4gICAgICAgIHQ9e3R9XG4gICAgICAvPlxuICAgICk7XG4gIH1cbn1cbiJdfQ== */",
28
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
29
+ });
30
+ class GiteaAuthenticationPage extends _react.default.Component {
31
+ constructor(...args) {
32
+ super(...args);
33
+ _defineProperty(this, "state", {});
34
+ _defineProperty(this, "handleLogin", e => {
35
+ e.preventDefault();
36
+ this.auth.authenticate({
37
+ scope: 'repository'
38
+ }, (err, data) => {
39
+ if (err) {
40
+ this.setState({
41
+ loginError: err.toString()
42
+ });
43
+ return;
44
+ }
45
+ this.props.onLogin(data);
46
+ });
47
+ });
48
+ }
49
+ componentDidMount() {
50
+ const {
51
+ base_url = 'https://try.gitea.io',
52
+ app_id = ''
53
+ } = this.props.config.backend;
54
+ this.auth = new _decapCmsLibAuth.PkceAuthenticator({
55
+ base_url,
56
+ auth_endpoint: 'login/oauth/authorize',
57
+ app_id,
58
+ auth_token_endpoint: 'login/oauth/access_token'
59
+ });
60
+ // Complete authentication if we were redirected back to from the provider.
61
+ this.auth.completeAuth((err, data) => {
62
+ if (err) {
63
+ this.setState({
64
+ loginError: err.toString()
65
+ });
66
+ return;
67
+ } else if (data) {
68
+ this.props.onLogin(data);
69
+ }
70
+ });
71
+ }
72
+ render() {
73
+ const {
74
+ inProgress,
75
+ config,
76
+ t
77
+ } = this.props;
78
+ return (0, _react2.jsx)(_decapCmsUiDefault.AuthenticationPage, {
79
+ onLogin: this.handleLogin,
80
+ loginDisabled: inProgress,
81
+ loginErrorMessage: this.state.loginError,
82
+ logoUrl: config.logoUrl,
83
+ siteUrl: config.siteUrl,
84
+ renderButtonContent: () => (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)(LoginButtonIcon, {
85
+ type: "gitea"
86
+ }), ' ', inProgress ? t('auth.loggingIn') : t('auth.loginWithGitea')),
87
+ t: t
88
+ });
89
+ }
90
+ }
91
+ exports.default = GiteaAuthenticationPage;
92
+ _defineProperty(GiteaAuthenticationPage, "propTypes", {
93
+ inProgress: _propTypes.default.bool,
94
+ config: _propTypes.default.object.isRequired,
95
+ onLogin: _propTypes.default.func.isRequired,
96
+ t: _propTypes.default.func.isRequired
97
+ });