Skip to content

Commit c38654c

Browse files
committed
코드 스타일 변경
1 parent dc89046 commit c38654c

File tree

6 files changed

+111
-108
lines changed

6 files changed

+111
-108
lines changed

jsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"experimentalDecorators": true,
4+
}
5+
}

src/main/apis/tistory-api.js

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ const appInfo = require('../appInfo')
99
const ExternalOAuth2 = require('../oauth/ExternalOAuth2');
1010
const OAuthRequestManager = require('../oauth/OAuthRequestManager');
1111

12-
const errorHandler = (res) => {
12+
const BASE_URL = 'https://www.tistory.com/apis'
13+
const PROVIDER_ID = 'tistory'
14+
15+
function _errorHandler(res) {
1316
if (!res.ok) {
1417
console.error("fetch failed", res)
1518
res.text().then(text => console.error("fetch body", text))
@@ -19,10 +22,44 @@ const errorHandler = (res) => {
1922
return res.json()
2023
}
2124

22-
const BASE_URL = 'https://www.tistory.com/apis'
23-
const PROVIDER_ID = 'tistory'
25+
function _uploadFile(accessToken, blogName, fileBlob, fileOption) {
26+
let formdata = new FormData();
27+
formdata.append("access_token", accessToken)
28+
formdata.append("output", "json")
29+
formdata.append("blogName", blogName)
30+
formdata.append("uploadedfile", fileBlob, fileOption)
31+
32+
return fetch(BASE_URL + "/post/attach", {
33+
method: 'post',
34+
body: formdata
35+
})
36+
.then(_errorHandler)
37+
.then(res => res.tistory.url)
38+
}
2439

25-
const requestAuth = (successHandler, failureHandler) => {
40+
41+
function _tistoryPostToEditorPost(post) {
42+
return {
43+
id: post.id,
44+
url: post.postUrl,
45+
title: post.title,
46+
date: post.date,
47+
categoryId: post.categoryId,
48+
state: post.visibility > 0? 'published' : 'draft',
49+
tags: post.tags && post.tags.tag? [].concat(post.tags.tag) : [],
50+
content: post.content? post.content : ''
51+
}
52+
}
53+
54+
function _tistoryPostsToEditorPosts(tistoryPosts) {
55+
let posts = tistoryPosts? [].concat(tistoryPosts) : []
56+
return posts.map(_tistoryPostToEditorPost)
57+
}
58+
59+
60+
61+
62+
function requestAuth(successHandler, failureHandler) {
2663
const oauthInfoReader = new OauthInfoReader()
2764
const oauth2 = new ExternalOAuth2(oauthInfoReader.getTistory())
2865
OAuthRequestManager.saveRequestInfo("oauth", (searchParams) => {
@@ -46,7 +83,7 @@ const requestAuth = (successHandler, failureHandler) => {
4683
oauth2.requestAuth({})
4784
}
4885

49-
const fetchBlogInfo = (auth) => {
86+
function fetchBlogInfo(auth) {
5087
return fetch(BASE_URL + "/blog/info?" + querystring.stringify({
5188
access_token: auth.access_token,
5289
output: "json"
@@ -55,10 +92,10 @@ const fetchBlogInfo = (auth) => {
5592
'User-Agent': appInfo.userAgent
5693
}
5794
})
58-
.then(errorHandler)
95+
.then(_errorHandler)
5996
}
6097

61-
const fetchUser = (auth) => {
98+
function fetchUser(auth) {
6299
return fetch(BASE_URL + "/user?" + querystring.stringify({
63100
access_token: auth.access_token,
64101
output: "json"
@@ -67,26 +104,9 @@ const fetchUser = (auth) => {
67104
'User-Agent': appInfo.userAgent
68105
}
69106
})
70-
.then(errorHandler)
107+
.then(_errorHandler)
71108
}
72109

73-
function _tistoryPostToEditorPost(post) {
74-
return {
75-
id: post.id,
76-
url: post.postUrl,
77-
title: post.title,
78-
date: post.date,
79-
categoryId: post.categoryId,
80-
state: post.visibility > 0? 'published' : 'draft',
81-
tags: post.tags && post.tags.tag? [].concat(post.tags.tag) : [],
82-
content: post.content? post.content : ''
83-
}
84-
}
85-
86-
function _tistoryPostsToEditorPosts(tistoryPosts) {
87-
let posts = tistoryPosts? [].concat(tistoryPosts) : []
88-
return posts.map(_tistoryPostToEditorPost)
89-
}
90110

91111
const fetchPosts = (auth, blogName, options) => {
92112
return fetch(BASE_URL + "/post/list?" + querystring.stringify({
@@ -100,15 +120,15 @@ const fetchPosts = (auth, blogName, options) => {
100120
'User-Agent': appInfo.userAgent
101121
}
102122
})
103-
.then(errorHandler)
123+
.then(_errorHandler)
104124
.then(res => ({
105125
page: res.tistory.item.page,
106126
posts: _tistoryPostsToEditorPosts(res.tistory.item.posts),
107127
hasNext: res.tistory.item.totalCount > res.tistory.item.page * res.tistory.item.count
108128
}))
109129
}
110130

111-
const fetchPost = (auth, blogName, postId) => {
131+
function fetchPost(auth, blogName, postId) {
112132
return fetch(BASE_URL + "/post/read?" + querystring.stringify({
113133
access_token: auth.access_token,
114134
output: "json",
@@ -119,13 +139,13 @@ const fetchPost = (auth, blogName, postId) => {
119139
'User-Agent': appInfo.userAgent
120140
}
121141
})
122-
.then(errorHandler)
142+
.then(_errorHandler)
123143
.then(res => ({
124144
post: _tistoryPostToEditorPost(res.tistory.item)
125145
}))
126146
}
127147

128-
const fetchCategories = (auth, blogName) => {
148+
function fetchCategories(auth, blogName) {
129149
return fetch(BASE_URL + "/category/list?" + querystring.stringify({
130150
access_token: auth.access_token,
131151
output: "json",
@@ -135,11 +155,11 @@ const fetchCategories = (auth, blogName) => {
135155
'User-Agent': appInfo.userAgent
136156
}
137157
})
138-
.then(errorHandler)
158+
.then(_errorHandler)
139159
.then(res => res.tistory.item.categories)
140160
}
141161

142-
const savePost = (auth, blogName, post) => {
162+
function savePost(auth, blogName, post) {
143163
let formdata = makePostFormData(auth, blogName, post)
144164
formdata.append("postId", post.id)
145165

@@ -151,11 +171,11 @@ const savePost = (auth, blogName, post) => {
151171
'User-Agent': appInfo.userAgent
152172
}
153173
})
154-
.then(errorHandler)
174+
.then(_errorHandler)
155175
.then(res => fetchPost(auth, blogName, res.tistory.postId))
156176
}
157177

158-
const addPost = (auth, blogName, post) => {
178+
function addPost(auth, blogName, post) {
159179
let formdata = makePostFormData(auth, blogName, post)
160180

161181
return fetch(BASE_URL + "/post/write", {
@@ -166,11 +186,11 @@ const addPost = (auth, blogName, post) => {
166186
'User-Agent': appInfo.userAgent
167187
}
168188
})
169-
.then(errorHandler)
189+
.then(_errorHandler)
170190
.then(res => fetchPost(auth, blogName, res.tistory.postId))
171191
}
172192

173-
const makePostFormData = (auth, blogName, post) => {
193+
function makePostFormData(auth, blogName, post) {
174194
let formdata = new FormData()
175195
formdata.append("access_token", auth.access_token)
176196
formdata.append("output", "json")
@@ -189,19 +209,19 @@ const makePostFormData = (auth, blogName, post) => {
189209
return formdata
190210
}
191211

192-
const uploadFile = (auth, blogName, filepath) => {
212+
function uploadFile(auth, blogName, filepath) {
193213
console.log("uploadFile", blogName, filepath)
194214
return _uploadFile(auth.access_token, blogName, fs.createReadStream(filepath))
195215
}
196216

197-
const uploadFileWithBuffer = (auth, blogName, buffer, options) => {
217+
function uploadFileWithBuffer(auth, blogName, buffer, options) {
198218
console.log("uploadFileWithClipboard", blogName)
199219
var imageStream = new stream.PassThrough()
200220
imageStream.end(buffer)
201221
return _uploadFile(auth.access_token, blogName, imageStream, options)
202222
}
203223

204-
const uploadFileWithBlob = (auth, blogName, blob, options) => {
224+
function uploadFileWithBlob(auth, blogName, blob, options) {
205225
console.log("uploadFileWithBlob", blogName)
206226
var imageStream = new stream.PassThrough()
207227
imageStream.end(blob.buffer)
@@ -212,24 +232,12 @@ const uploadFileWithBlob = (auth, blogName, blob, options) => {
212232
})
213233
}
214234

215-
const _uploadFile = (accessToken, blogName, fileBlob, fileOption) => {
216-
let formdata = new FormData();
217-
formdata.append("access_token", accessToken)
218-
formdata.append("output", "json")
219-
formdata.append("blogName", blogName)
220-
formdata.append("uploadedfile", fileBlob, fileOption)
221235

222-
return fetch(BASE_URL + "/post/attach", {
223-
method: 'post',
224-
body: formdata
225-
})
226-
.then(errorHandler)
227-
.then(res => res.tistory.url)
236+
function validateAuthInfo(auth) {
237+
return auth && auth.access_token
228238
}
229239

230-
const validateAuthInfo = (auth) => auth && auth.access_token
231-
232-
const fetchAccount = async (auth) => {
240+
async function fetchAccount(auth) {
233241
let user = {
234242
name: "tistory",
235243
image: null

src/main/apis/tumblr-api.js

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,7 @@ const OAuthRequestManager = require('../oauth/OAuthRequestManager');
66

77
const PROVIDER_ID = 'tumblr'
88

9-
const requestAuth = (successHandler, failureHandler) => {
10-
const oauthInfoReader = new OauthInfoReader()
11-
const oauth1 = new ExternalOAuth1(oauthInfoReader.getTumblr())
12-
oauth1.requestAuth((requestTokens) => {
13-
OAuthRequestManager.saveRequestInfo('oauth', (searchParams) => {
14-
const verifier = searchParams.get("oauth_verifier")
15-
oauth1.requestToken(verifier, requestTokens, (error, token, tokenSecret) => {
16-
if (error) {
17-
failureHandler()
18-
return
19-
}
20-
21-
successHandler({
22-
uuid: uuid(),
23-
provider: PROVIDER_ID,
24-
authInfo: {
25-
token, tokenSecret
26-
}
27-
})
28-
})
29-
})
30-
})
31-
32-
}
33-
34-
function createTumblrClient(auth) {
9+
function _createTumblrClient(auth) {
3510
const oauthReader = new OauthInfoReader()
3611
const tumblrInfo = oauthReader.getTumblr()
3712

@@ -46,10 +21,6 @@ function createTumblrClient(auth) {
4621
})
4722
}
4823

49-
const fetchUser = (auth) => {
50-
const client = createTumblrClient(auth)
51-
return client.userInfo()
52-
}
5324

5425
function _tumblrPostToEditorPost(post) {
5526
return ({
@@ -85,39 +56,72 @@ function _editorPostToTumblrPost(editorPost) {
8556
return tumblrPost
8657
}
8758

88-
const fetchPosts = (auth, blogName, options) => {
89-
const client = createTumblrClient(auth)
59+
function requestAuth(successHandler, failureHandler) {
60+
const oauthInfoReader = new OauthInfoReader()
61+
const oauth1 = new ExternalOAuth1(oauthInfoReader.getTumblr())
62+
oauth1.requestAuth((requestTokens) => {
63+
OAuthRequestManager.saveRequestInfo('oauth', (searchParams) => {
64+
const verifier = searchParams.get("oauth_verifier")
65+
oauth1.requestToken(verifier, requestTokens, (error, token, tokenSecret) => {
66+
if (error) {
67+
failureHandler()
68+
return
69+
}
70+
71+
successHandler({
72+
uuid: uuid(),
73+
provider: PROVIDER_ID,
74+
authInfo: {
75+
token, tokenSecret
76+
}
77+
})
78+
})
79+
})
80+
})
81+
82+
}
83+
84+
function fetchUser(auth) {
85+
const client = _createTumblrClient(auth)
86+
return client.userInfo()
87+
}
88+
89+
90+
function fetchPosts(auth, blogName, options) {
91+
const client = _createTumblrClient(auth)
9092
return client.blogPosts(blogName, options)
9193
.then(res => ({
9294
posts: _tumblrPostsToEditorPosts(res.posts),
9395
hasNext: res.blog.posts > options.offset + res.posts.length
9496
}))
9597
}
9698

97-
const fetchPost = (auth, blogName, postId) => {
98-
const client = createTumblrClient(auth)
99+
function fetchPost(auth, blogName, postId) {
100+
const client = _createTumblrClient(auth)
99101
return client.blogPosts(blogName, {id: postId})
100102
.then(res => ({
101103
post: _tumblrPostToEditorPost(res.posts[0])
102104
}))
103105
}
104106

105-
const addPost = async (auth, blogName, post) => {
106-
const client = createTumblrClient(auth)
107+
async function addPost(auth, blogName, post) {
108+
const client = _createTumblrClient(auth)
107109
const res = await client.createTextPost(blogName, _editorPostToTumblrPost(post))
108110
const fetchRes = await fetchPosts(auth, blogName, {offset:0, limit:1})
109111
return { post: fetchRes.posts[0] }
110112
}
111113

112-
const savePost = async (auth, blogName, post) => {
113-
const client = createTumblrClient(auth)
114+
async function savePost(auth, blogName, post) {
115+
const client = _createTumblrClient(auth)
114116
const res = await client.editPost(blogName, _editorPostToTumblrPost(post))
115117
return await fetchPost(auth, blogName, post.id)
116118
}
117119

118-
const validateAuthInfo = (auth) => auth && auth.token
120+
function validateAuthInfo(auth) {
121+
return auth && auth.token
122+
}
119123

120-
const fetchAccount = async (auth) => {
124+
async function fetchAccount(auth) {
121125
let blogs = []
122126
let username = ""
123127
try {

src/renderer/components/editor/tinymce/plugins/file-upload/plugin.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import React from 'react'
2-
import { unmountComponentAtNode } from 'react-dom'
3-
import autobind from 'autobind-decorator'
4-
5-
const plugin = function (editor) {
1+
export default function plugin(editor) {
62
editor.options.register("open_file_handler", {
73
processor: 'function',
84
default: () => {}
@@ -23,5 +19,3 @@ const plugin = function (editor) {
2319
}
2420
})
2521
}
26-
27-
export default plugin

src/renderer/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import { render } from 'react-dom'
32
import { createRoot } from 'react-dom/client'
43
import { Provider } from 'react-redux'
54

0 commit comments

Comments
 (0)