Skip to content

Commit f68ef39

Browse files
authored
Merge pull request #62 from Coding/define-app-lifecycle
定义 initialize 阶段;解决平台与开源版 API 分叉问题
2 parents 08ffc3d + 53cf988 commit f68ef39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+555
-697
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ build
33
**/*.md
44
.idea/
55
.vscode/
6+
.env
67
app/config.js
78
*.bak

app/backendAPI/fileAPI.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export function writeFile (path, content, base64) {
4646
}
4747

4848
export function readFile (path) {
49-
return request.get(`/workspaces/${config.spaceKey}/file/read`, {
49+
const url = config.isPlatform ?
50+
`/workspaces/${config.spaceKey}/read`
51+
: `/workspaces/${config.spaceKey}/file/read`
52+
53+
return request.get(url, {
5054
path: path,
5155
base64: false
5256
})

app/backendAPI/gitAPI.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export function gitCheckout (branch, remoteBranch) {
1919
}
2020

2121
export function gitCommit ({files, message}) {
22-
return request.post(`/git/${config.spaceKey}`, {files, message})
22+
const url = config.isPlatform ? `/git/${config.spaceKey}/commits` : `/git/${config.spaceKey}`
23+
return request.post(url, {files, message})
2324
}
2425

2526
export function gitPull () {
@@ -113,11 +114,15 @@ export function gitRebaseUpdate (lines) {
113114
}
114115

115116
export function gitCommitDiff ({ref}) {
116-
return request.get(`/git/${config.spaceKey}/diff`, {ref})
117+
return config.isPlatform ?
118+
request.diffFilesList(`/git/${config.spaceKey}/commits/${ref}`)
119+
: request.get(`/git/${config.spaceKey}/diff`, {ref})
117120
}
118121

119122
export function gitFileDiff ({ path, oldRef, newRef }) {
120-
return request.get(`/git/${config.spaceKey}/diff`, { path, oldRef, newRef })
123+
return config.isPlatform ?
124+
request.diff(`/git/${config.spaceKey}/commits/${oldRef}...${newRef}`, { path })
125+
: request.get(`/git/${config.spaceKey}/diff`, { path, oldRef, newRef })
121126
}
122127

123128
export function gitReadFile ({ref, path}) {

app/backendAPI/websocketClient.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ const _resetRetryDelay = () => {
2222

2323
const Client = {
2424
connect: function (connectCallback, errorCallback) {
25-
var socket = new SockJS(`${config.baseURL}/sockjs/`, {}, {server: `${config.spaceKey}`, transports: 'websocket'})
25+
const url = config.isPlatform ?
26+
`${config.wsURL}/sockjs/${config.spaceKey}`
27+
: `${config.baseURL}/sockjs/`
28+
29+
const socket = new SockJS(url, {}, {server: `${config.spaceKey}`, transports: 'websocket'})
2630
var stompClient = Stomp.over(socket)
2731

2832
return stompClient.connect({},

app/backendAPI/workspaceAPI.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,36 @@ import Client from './websocketClient'
55

66
var connectedResolve
77
export const websocketConnectedPromise = new Promise((rs, rj) => connectedResolve = rs)
8-
export function setupWorkspace () {
9-
return request.post(`/workspaces/${config.spaceKey}/setup`).then(({spaceKey, projectName, projectIconUrl}) => {
10-
// 1.
11-
var websocketPromise = new Promise(function (resolve, reject) {
12-
Client.connect(function () {
13-
connectedResolve(this)
14-
resolve(true)
15-
})
16-
})
17-
18-
// 2.
19-
var settingsPromise = request.get(`/workspaces/${config.spaceKey}/settings`).then(({content}) => {
20-
return JSON.parse(content)
21-
})
228

23-
return Promise.all([websocketPromise, settingsPromise]).then(([isConnected, settings]) => {
24-
return {
25-
projectName,
26-
spaceKey,
27-
projectIconUrl,
28-
settings
29-
}
30-
})
31-
})
9+
export function isWorkspaceExist () {
10+
return request.get(`/workspaces/${config.spaceKey}`).catch(() => false).then(() => true)
3211
}
3312

34-
export function getWorkspaces () {
35-
return request.get(`/workspaces`)
13+
export function setupWorkspace () {
14+
return config.isPlatform ?
15+
request.post('/workspaces', {spaceKey: config.spaceKey})
16+
: request.post(`/workspaces/${config.spaceKey}/setup`)
3617
}
3718

38-
export function createWorkspace (url) {
39-
return request.post('/workspaces', {url})
19+
export function connectWebsocketClient () {
20+
return new Promise(function (resolve, reject) {
21+
Client.connect(function () {
22+
connectedResolve(this)
23+
resolve(true)
24+
})
25+
})
4026
}
4127

42-
export function deleteWorkspace (spaceKey) {
43-
return request.delete(`/workspaces/${spaceKey}`)
28+
export function getSettings () {
29+
return request.get(`/workspaces/${config.spaceKey}/settings`).then(({ content={} }) => {
30+
return JSON.parse(content)
31+
})
4432
}
4533

46-
export function getPublicKey () {
47-
return request.get('/user?public_key')
34+
// Switch back to old version
35+
export function switchVersion () {
36+
return request.put('/versions')
37+
.then((res) => {
38+
window.location.reload()
39+
})
4840
}

app/commands/commandBindings/file.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ export default {
7777

7878
} else {
7979
api.writeFile(activeTab.path, content)
80-
.then(() => dispatch(Tab.actions.updateTabFlags(activeTab.id, 'modified', false)))
80+
.then(() => {
81+
dispatch(Tab.actions.updateTabFlags(activeTab.id, 'modified', false))
82+
dispatch(Tab.actions.updateTab({
83+
id: activeTab.id, content: { body: content }
84+
}))
85+
})
8186
}
8287

8388
},

0 commit comments

Comments
 (0)