Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/storage/utils/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
* governing permissions and limitations under the License.
*/
export async function invalidateCollab(api, url, env) {
if (!url.endsWith('.html')) {
// collab only deals with .html files, no need to invalidate anything else
return;
}

const invPath = `/api/v1/${api}?doc=${url}`;

// Use dacollab service binding, hostname is not relevant
Expand Down
47 changes: 47 additions & 0 deletions test/storage/utils/object.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/* eslint-env mocha */
import assert from 'assert';
import { invalidateCollab } from '../../../src/storage/utils/object.js';

describe('Storage Object Utils tests', () => {
function setupEnv() {
const called = [];
const dacollab = {
fetch: async (url) => {
console.log(`invalidate called with ${url}`);
called.push(url);
},
};
const env = { dacollab };
return { called, env };
}

it('Should invalidate', async () => {
const { called, env } = setupEnv();

assert.strictEqual(called.length, 0, 'precondition');
await invalidateCollab('syncAdmin', 'https://admin.da.live/source/a/b/c.html', env);
assert.strictEqual(called.length, 1);
assert.strictEqual(called[0], 'https://localhost/api/v1/syncAdmin?doc=https://admin.da.live/source/a/b/c.html');
});

it('Should not invalidate non-html documents', async () => {
const { called, env } = setupEnv();

assert.strictEqual(called.length, 0, 'precondition');
await invalidateCollab('syncAdmin', 'https://admin.da.live/source/a/b/c.jpg', env);
await invalidateCollab('syncAdmin', 'https://admin.da.live/source/a/b/c/d', env);
assert.strictEqual(called.length, 0, 'should not have invalidated anything');
});
});