Files
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

59 lines
1.8 KiB
JavaScript

import { cli } from '@jackwener/opencli/registry';
cli({
site: 'instagram',
name: 'collection-create',
access: 'write',
description: 'Create a new Instagram saved-posts collection (folder)',
domain: 'www.instagram.com',
args: [
{
name: 'name',
required: true,
positional: true,
help: 'Name of the collection to create',
},
],
columns: ['status', 'collectionId', 'collectionName', 'mediaCount'],
pipeline: [
{ navigate: 'https://www.instagram.com' },
{ evaluate: `(async () => {
const name = \${{ args.name | json }};
if (!name || !String(name).trim()) {
throw new Error('Collection name cannot be empty');
}
const trimmed = String(name).trim();
const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
if (!csrf) {
throw new Error('csrftoken cookie missing - make sure you are logged in to Instagram');
}
const fd = new FormData();
fd.append('name', trimmed);
fd.append('module_name', 'collection_create');
const res = await fetch('https://www.instagram.com/api/v1/collections/create/', {
method: 'POST',
credentials: 'include',
headers: {
'X-IG-App-ID': '936619743392459',
'X-CSRFToken': csrf,
},
body: fd,
});
if (!res.ok) {
const body = await res.text().catch(() => '');
throw new Error('Failed to create collection: HTTP ' + res.status + (body ? ' - ' + body.slice(0, 200) : ''));
}
const d = await res.json();
if (d?.status && d.status !== 'ok') {
throw new Error('Instagram returned non-ok status: ' + JSON.stringify(d).slice(0, 300));
}
return [{
status: 'Created',
collectionId: String(d?.collection_id ?? ''),
collectionName: String(d?.collection_name ?? trimmed),
mediaCount: d?.collection_media_count ?? 0,
}];
})()
` },
],
});