Created
May 28, 2024 06:59
-
-
Save badboy-tian/3bb44139d2346f159fd4cd9e5cf5aecb to your computer and use it in GitHub Desktop.
ParseError: Object not found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Parse = require("parse/node") | |
const moment = require("moment") | |
Parse.initialize("debug_appid", "debug_key", "debug_masterKey") | |
Parse.serverURL = "http://localhost:1337/parse" | |
const body = { | |
name: "SaveAudio", | |
data: "{\"__after\":\"1716788669509,2cf6e3698932972402fa3ca2405b437dc3ac727a\",\"isDeleted\":false,\"name\":\"好的呢,宝宝\",\"duration\":2,\"url\":\"http://file2.xxxx.com/FdD9KwF4xNgBHTiGcJByMNs6P470XNFp/20240405195209.mp3\",\"user\":{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"65de1d08caa7af401d105a56\"},\"pack\":{\"__type\":\"Pointer\",\"className\":\"SaveAudioPack\",\"objectId\":\"65e9fcec4567a26864d47d2b\"},\"objectId\":\"66541dbdffead844f1339e3c\",\"createdAt\":\"2024-05-27T05:44:29.504Z\",\"updatedAt\":\"2024-05-27T05:44:29.504Z\"}" | |
}; | |
async function test() { | |
const name = body.name; | |
const data = JSON.parse(body.data); | |
const testObject = new Parse.Object(name); | |
testObject.id = data.objectId; | |
const entries = Object.entries(data); | |
const map = []; | |
for (let i = 0; i < entries.length; i++) { | |
map.push({ | |
key: entries[i][0], | |
value: entries[i][1] | |
}) | |
} | |
for (let i = 0; i < map.length; i++) { | |
const key = map[i].key; | |
const value = map[i].value; | |
if (key === "__after") { | |
continue; | |
} | |
if (key === "createdAt" || key === "updatedAt") { | |
testObject.set(key, moment(value).toDate()); | |
continue; | |
} | |
//处理Pointer | |
if (typeof value === "object" && value.__type === "Pointer") { | |
let className = value.className; | |
if (className === "_File") { | |
className = "AVFile"; | |
} | |
const InnerObject = Parse.Object.extend(className); | |
testObject.set(key, InnerObject.createWithoutData(value.objectId)) | |
} else { | |
testObject.set(key, value); | |
} | |
} | |
console.log(testObject.toJSON()) | |
await testObject.save(null, {useMasterKey: true}); | |
} | |
test(); |
Author
badboy-tian
commented
May 28, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment