|
@@ -1,4 +1,10 @@
|
|
|
// CloudObject.ts
|
|
|
+
|
|
|
+let serverURL = `https://dev.fmode.cn/parse`;
|
|
|
+if(location.protocol=="http:"){
|
|
|
+ serverURL = `http://dev.fmode.cn:1337/parse`;
|
|
|
+}
|
|
|
+
|
|
|
export class CloudObject {
|
|
|
className: string;
|
|
|
id: string | null = null;
|
|
@@ -29,7 +35,7 @@ export class CloudObject {
|
|
|
|
|
|
async save() {
|
|
|
let method = "POST";
|
|
|
- let url = `https://dev.fmode.cn/parse/classes/${this.className}`;
|
|
|
+ let url = serverURL + `/classes/${this.className}`;
|
|
|
|
|
|
// 更新
|
|
|
if (this.id) {
|
|
@@ -61,7 +67,7 @@ export class CloudObject {
|
|
|
|
|
|
async destroy() {
|
|
|
if (!this.id) return;
|
|
|
- const response = await fetch(`https://dev.fmode.cn/parse/classes/${this.className}/${this.id}`, {
|
|
|
+ const response = await fetch(serverURL + `/classes/${this.className}/${this.id}`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev"
|
|
|
},
|
|
@@ -117,7 +123,7 @@ export class CloudQuery {
|
|
|
}
|
|
|
|
|
|
async get(id: string) {
|
|
|
- const url = `https://dev.fmode.cn/parse/classes/${this.className}/${id}?`;
|
|
|
+ const url = serverURL + `/classes/${this.className}/${id}?`;
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
headers: {
|
|
@@ -139,7 +145,7 @@ export class CloudQuery {
|
|
|
}
|
|
|
|
|
|
async find():Promise<Array<CloudObject>> {
|
|
|
- let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
|
+ let url = serverURL + `/classes/${this.className}?`;
|
|
|
|
|
|
let queryStr = ``
|
|
|
Object.keys(this.queryParams).forEach(key=>{
|
|
@@ -154,7 +160,7 @@ export class CloudQuery {
|
|
|
}
|
|
|
})
|
|
|
// if (Object.keys(this.queryParams["where"]).length) {
|
|
|
-
|
|
|
+
|
|
|
// }
|
|
|
|
|
|
const response = await fetch(url, {
|
|
@@ -176,7 +182,7 @@ export class CloudQuery {
|
|
|
|
|
|
|
|
|
async first() {
|
|
|
- let url = `https://dev.fmode.cn/parse/classes/${this.className}?`;
|
|
|
+ let url = serverURL + `/classes/${this.className}?`;
|
|
|
|
|
|
if (Object.keys(this.queryParams["where"]).length) {
|
|
|
const whereStr = JSON.stringify(this.queryParams["where"]);
|
|
@@ -236,7 +242,7 @@ export class CloudUser extends CloudObject {
|
|
|
return null;
|
|
|
}
|
|
|
return this;
|
|
|
- // const response = await fetch(`https://dev.fmode.cn/parse/users/me`, {
|
|
|
+ // const response = await fetch(serverURL + `/users/me`, {
|
|
|
// headers: {
|
|
|
// "x-parse-application-id": "dev",
|
|
|
// "x-parse-session-token": this.sessionToken // 使用sessionToken进行身份验证
|
|
@@ -254,7 +260,7 @@ export class CloudUser extends CloudObject {
|
|
|
|
|
|
/** 登录 */
|
|
|
async login(username: string, password: string):Promise<CloudUser|null> {
|
|
|
- const response = await fetch(`https://dev.fmode.cn/parse/login`, {
|
|
|
+ const response = await fetch(serverURL + `/login`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev",
|
|
|
"Content-Type": "application/json"
|
|
@@ -268,7 +274,7 @@ export class CloudUser extends CloudObject {
|
|
|
console.error(result?.error);
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 设置用户信息
|
|
|
this.id = result?.objectId;
|
|
|
this.sessionToken = result?.sessionToken;
|
|
@@ -286,7 +292,7 @@ export class CloudUser extends CloudObject {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const response = await fetch(`https://dev.fmode.cn/parse/logout`, {
|
|
|
+ const response = await fetch(serverURL + `/logout`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev",
|
|
|
"x-parse-session-token": this.sessionToken
|
|
@@ -324,7 +330,7 @@ export class CloudUser extends CloudObject {
|
|
|
...additionalData // 合并额外的用户数据
|
|
|
};
|
|
|
|
|
|
- const response = await fetch(`https://dev.fmode.cn/parse/users`, {
|
|
|
+ const response = await fetch(serverURL + `/users`, {
|
|
|
headers: {
|
|
|
"x-parse-application-id": "dev",
|
|
|
"Content-Type": "application/json"
|
|
@@ -351,14 +357,14 @@ export class CloudUser extends CloudObject {
|
|
|
|
|
|
override async save() {
|
|
|
let method = "POST";
|
|
|
- let url = `https://dev.fmode.cn/parse/users`;
|
|
|
-
|
|
|
+ let url = serverURL + `/users`;
|
|
|
+
|
|
|
// 更新用户信息
|
|
|
if (this.id) {
|
|
|
url += `/${this.id}`;
|
|
|
method = "PUT";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
let data:any = JSON.parse(JSON.stringify(this.data))
|
|
|
delete data.createdAt
|
|
|
delete data.updatedAt
|
|
@@ -377,7 +383,7 @@ export class CloudUser extends CloudObject {
|
|
|
mode: "cors",
|
|
|
credentials: "omit"
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
const result = await response?.json();
|
|
|
if (result?.error) {
|
|
|
console.error(result?.error);
|
|
@@ -417,4 +423,4 @@ export class CloudApi{
|
|
|
let json = await response.json();
|
|
|
return json
|
|
|
}
|
|
|
-}
|
|
|
+}
|