missions api2
This commit is contained in:
parent
d9d8a402bf
commit
b4188003e1
@ -30,12 +30,13 @@ export class OutlineService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Create a collection in Outline based on the mission
|
// Create a collection in Outline based on the mission
|
||||||
|
// Note: According to Outline API, setting permission to "private" makes it private
|
||||||
const payload = {
|
const payload = {
|
||||||
name: collectionName,
|
name: collectionName,
|
||||||
description: mission.description || 'Mission documentation',
|
description: mission.description || 'Mission documentation',
|
||||||
color: '#4f46e5', // Indigo color as default
|
color: '#4f46e5', // Indigo color as default
|
||||||
permission: 'read_write',
|
permission: "private", // This is the correct way to make it private
|
||||||
private: true // Make the collection private
|
private: true // Keep this for backward compatibility
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Sending to Outline API:', JSON.stringify(payload, null, 2));
|
console.log('Sending to Outline API:', JSON.stringify(payload, null, 2));
|
||||||
@ -53,10 +54,18 @@ export class OutlineService {
|
|||||||
|
|
||||||
console.log('Outline API response:', JSON.stringify(response.data, null, 2));
|
console.log('Outline API response:', JSON.stringify(response.data, null, 2));
|
||||||
|
|
||||||
if (response.data && response.data.data && response.data.data.id) {
|
// Create a default document in the collection
|
||||||
return response.data.data.id;
|
if (response.data && (response.data.data?.id || response.data.id)) {
|
||||||
} else if (response.data && response.data.id) {
|
const collectionId = response.data.data?.id || response.data.id;
|
||||||
return response.data.id;
|
|
||||||
|
try {
|
||||||
|
// Try to create a welcome document in the collection
|
||||||
|
await this.createWelcomeDocument(collectionId, collectionName);
|
||||||
|
} catch (docError) {
|
||||||
|
console.warn('Failed to create welcome document, but collection was created:', docError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return collectionId;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Failed to get collection ID from Outline API response');
|
throw new Error('Failed to get collection ID from Outline API response');
|
||||||
}
|
}
|
||||||
@ -78,6 +87,31 @@ export class OutlineService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper method to create a welcome document in a collection
|
||||||
|
private async createWelcomeDocument(collectionId: string, collectionName: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await axios.post(
|
||||||
|
`${this.apiUrl}/documents.create`,
|
||||||
|
{
|
||||||
|
title: `Welcome to ${collectionName}`,
|
||||||
|
text: `# Welcome to ${collectionName}\n\nThis is your new private collection in Outline. Here you can store and share documents related to this mission.\n\n## Getting Started\n\n- Use the + button to create new documents\n- Organize documents with headers and lists\n- Share this collection only with team members involved in this mission`,
|
||||||
|
collectionId: collectionId,
|
||||||
|
publish: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${this.apiToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Created welcome document with ID:', response.data?.data?.id || response.data?.id);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to create welcome document:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async deleteCollection(collectionId: string): Promise<boolean> {
|
async deleteCollection(collectionId: string): Promise<boolean> {
|
||||||
if (!this.apiToken) {
|
if (!this.apiToken) {
|
||||||
throw new Error('Outline API token is not configured');
|
throw new Error('Outline API token is not configured');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user