@fileverse/api 0.0.8 → 0.0.10
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/dist/cli/index.js +8 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +18119 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/commands/index.js +31 -2
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +81 -2
- package/dist/index.js.map +1 -1
- package/dist/worker.js +81 -2
- package/dist/worker.js.map +1 -1
- package/package.json +4 -3
package/dist/worker.js
CHANGED
|
@@ -111,7 +111,12 @@ var init_config = __esm({
|
|
|
111
111
|
init_constants();
|
|
112
112
|
projectEnvPath = path2.join(process.cwd(), "config", ".env");
|
|
113
113
|
userEnvPath = path2.join(os.homedir(), ".fileverse", ".env");
|
|
114
|
-
|
|
114
|
+
if (typeof globalThis.process !== "undefined" && typeof globalThis.process.cwd === "function") {
|
|
115
|
+
try {
|
|
116
|
+
loadConfig(false);
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
}
|
|
115
120
|
config = {
|
|
116
121
|
...STATIC_CONFIG,
|
|
117
122
|
get SERVICE_NAME() {
|
|
@@ -964,6 +969,29 @@ var init_events_model = __esm({
|
|
|
964
969
|
`;
|
|
965
970
|
await QueryBuilder.execute(sql, [Date.now(), _id]);
|
|
966
971
|
}
|
|
972
|
+
static async markSubmitted(_id) {
|
|
973
|
+
const sql = `
|
|
974
|
+
UPDATE ${this.TABLE}
|
|
975
|
+
SET status = 'submitted',
|
|
976
|
+
lockedAt = NULL
|
|
977
|
+
WHERE _id = ?
|
|
978
|
+
`;
|
|
979
|
+
await QueryBuilder.execute(sql, [_id]);
|
|
980
|
+
}
|
|
981
|
+
static async findNextSubmitted(lockedFileIds) {
|
|
982
|
+
const exclusionClause = lockedFileIds.length > 0 ? `AND fileId NOT IN (${lockedFileIds.map(() => "?").join(", ")})` : "";
|
|
983
|
+
const sql = `
|
|
984
|
+
SELECT * FROM ${this.TABLE}
|
|
985
|
+
WHERE status = 'submitted'
|
|
986
|
+
AND userOpHash IS NOT NULL
|
|
987
|
+
${exclusionClause}
|
|
988
|
+
ORDER BY timestamp ASC
|
|
989
|
+
LIMIT 1
|
|
990
|
+
`;
|
|
991
|
+
const params = [...lockedFileIds];
|
|
992
|
+
const row = await QueryBuilder.selectOne(sql, params);
|
|
993
|
+
return row ? this.parseEvent(row) : void 0;
|
|
994
|
+
}
|
|
967
995
|
static async markProcessed(_id) {
|
|
968
996
|
const sql = `
|
|
969
997
|
UPDATE ${this.TABLE}
|
|
@@ -2721,6 +2749,56 @@ var init_file_manager = __esm({
|
|
|
2721
2749
|
metadata
|
|
2722
2750
|
};
|
|
2723
2751
|
}
|
|
2752
|
+
async submitUpdateFile(file) {
|
|
2753
|
+
logger.debug(`Submitting update for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2754
|
+
const { encryptedSecretKey, nonce, secretKey } = await generateLinkKeyMaterial({
|
|
2755
|
+
ddocId: file.ddocId,
|
|
2756
|
+
linkKey: file.linkKey,
|
|
2757
|
+
linkKeyNonce: file.linkKeyNonce
|
|
2758
|
+
});
|
|
2759
|
+
const yjsContent = markdownToYjs(file.content);
|
|
2760
|
+
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2761
|
+
const commentKey = toUint8Array2(file.commentKey);
|
|
2762
|
+
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
2763
|
+
const linkLock = buildLinklock(secretKey, toUint8Array2(key), commentKey);
|
|
2764
|
+
const encryptedTitle = await encryptTitleWithFileKey({
|
|
2765
|
+
title: file.title || "Untitled",
|
|
2766
|
+
key
|
|
2767
|
+
});
|
|
2768
|
+
const metadata = buildFileMetadata({
|
|
2769
|
+
encryptedTitle,
|
|
2770
|
+
encryptedFileSize: encryptedFile.size,
|
|
2771
|
+
appLock,
|
|
2772
|
+
ownerLock,
|
|
2773
|
+
ddocId: file.ddocId,
|
|
2774
|
+
nonce: fromUint8Array2(nonce),
|
|
2775
|
+
owner: this.agentClient.getAgentAddress()
|
|
2776
|
+
});
|
|
2777
|
+
const authParams = await this.getAuthParams();
|
|
2778
|
+
const { metadataHash, contentHash, gateHash } = await uploadAllFilesToIPFS(
|
|
2779
|
+
{ metadata, encryptedFile, linkLock, ddocId: file.ddocId },
|
|
2780
|
+
authParams
|
|
2781
|
+
);
|
|
2782
|
+
const callData = prepareCallData({
|
|
2783
|
+
metadataHash,
|
|
2784
|
+
contentHash,
|
|
2785
|
+
gateHash,
|
|
2786
|
+
appFileId: file.ddocId,
|
|
2787
|
+
fileId: file.onChainFileId
|
|
2788
|
+
});
|
|
2789
|
+
const userOpHash = await this.sendFileOperation(callData);
|
|
2790
|
+
logger.debug(`Submitted update user op for file ${file.ddocId}`);
|
|
2791
|
+
return { userOpHash, metadata };
|
|
2792
|
+
}
|
|
2793
|
+
async submitDeleteFile(file) {
|
|
2794
|
+
logger.debug(`Submitting delete for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2795
|
+
const callData = prepareDeleteFileCallData({
|
|
2796
|
+
onChainFileId: file.onChainFileId
|
|
2797
|
+
});
|
|
2798
|
+
const userOpHash = await this.sendFileOperation(callData);
|
|
2799
|
+
logger.debug(`Submitted delete user op for file ${file.ddocId}`);
|
|
2800
|
+
return { userOpHash };
|
|
2801
|
+
}
|
|
2724
2802
|
async updateFile(file) {
|
|
2725
2803
|
logger.debug(`Updating file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2726
2804
|
const { encryptedSecretKey, nonce, secretKey } = await generateLinkKeyMaterial({
|
|
@@ -2824,6 +2902,7 @@ var init_publish = __esm({
|
|
|
2824
2902
|
init_smart_agent();
|
|
2825
2903
|
init_file_manager();
|
|
2826
2904
|
init_config();
|
|
2905
|
+
init_pimlico_utils();
|
|
2827
2906
|
createFileManager = async (portalSeed, portalAddress, ucanSecret, privateAccountKey) => {
|
|
2828
2907
|
const keyPair = ucans2.EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret), {
|
|
2829
2908
|
exportable: true
|
|
@@ -3416,7 +3495,7 @@ CREATE TABLE IF NOT EXISTS events (
|
|
|
3416
3495
|
type TEXT NOT NULL CHECK (type IN ('create', 'update', 'delete')),
|
|
3417
3496
|
timestamp BIGINT NOT NULL,
|
|
3418
3497
|
fileId TEXT NOT NULL,
|
|
3419
|
-
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'processed', 'failed')),
|
|
3498
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'submitted', 'processed', 'failed')),
|
|
3420
3499
|
retryCount INTEGER NOT NULL DEFAULT 0,
|
|
3421
3500
|
lastError TEXT,
|
|
3422
3501
|
lockedAt BIGINT,
|