PageSourceSearch

https://smrtbld.ai/js/api/onedrive-import.js

js smrtbld.ai collected 2026-10-05 15:09:04 UTC 3,319 bytes, 88 lines download raw bytes

1/**
2 * OneDrive Import API — Pure functions for importing OneDrive files into SmartBuild.
3 *
4 * Calls the backend OneDriveController which handles:
5 *   1. Download file bytes from OneDrive pre-auth URL
6 *   2. Upload to Azure Blob Storage
7 *   3. Create DB record (project file or task document)
8 *
9 * Usage:
10 *   import { importToProjectFolder, importToTask } from '../api/onedrive-import.js';
11 *   const result = await importToProjectFolder(downloadUrl, fileName, folderId, projectId);
12 */
13
14import { ApiClient } from './base.js';
15import { config } from '../config.js';
16
17const api = new ApiClient();
18
19/**
20 * Import a OneDrive file to a project folder.
21 * @param {string} downloadUrl - Pre-authenticated OneDrive download URL
22 * @param {string} fileName - Original filename from OneDrive
23 * @param {number} folderId - Target ProjectFolderID
24 * @param {number} projectId - Project ID
25 * @param {object} [options] - Optional title and description
26 * @returns {Promise<{success, fileId, fileName, title, saveType}>}
27 */
28export async function importToProjectFolder(downloadUrl, fileName, folderId, projectId, options = {}) {
29    return api.post(`${config.apiPrefix}/onedrive/import`, {
30        downloadUrl,
31        fileName,
32        saveType: 'PFOLDER',
33        targetId: folderId,
34        projectId,
35        title: options.title || null,
36        description: options.description || null,
37    });
38}
39
40/**
41 * Import a OneDrive file to a project task (RFI, SI, CHG — anything in
42 * becc_pm_projecttasks_docs).
43 *
44 * NOT for submittals — their documents live in becc_pm_projectdocctrl_doc.
45 * Use importToSubmittal() for those or the file lands in a table the submittal
46 * detail never reads.
47 *
48 * @param {string} downloadUrl - Pre-authenticated OneDrive download URL
49 * @param {string} fileName - Original filename from OneDrive
50 * @param {number} taskId - Target ProjectTaskID
51 * @param {object} [options] - Optional title, description, projectId
52 * @returns {Promise<{success, fileId, fileName, title, saveType}>}
53 */
54export async function importToTask(downloadUrl, fileName, taskId, options = {}) {
55    return api.post(`${config.apiPrefix}/onedrive/import`, {
56        downloadUrl,
57        fileName,
58        saveType: 'TASK',
59        targetId: taskId,
60        projectId: options.projectId || 0,
61        title: options.title || null,
62        description: options.description || null,
63    });
64}
65
66/**
67 * Import a OneDrive file to a submittal.
68 *
69 * Separate from importToTask because submittal documents are stored in
70 * becc_pm_projectdocctrl_doc rather than becc_pm_projecttasks_docs.
71 *
72 * @param {string} downloadUrl - Pre-authenticated OneDrive download URL
73 * @param {string} fileName - Original filename from OneDrive
74 * @param {number} submittalId - Target ProjectDocCtrlID
75 * @param {object} [options] - Optional title, description, projectId
76 * @returns {Promise<{success, fileId, fileName, title, saveType}>}
77 */
78export async function importToSubmittal(downloadUrl, fileName, submittalId, options = {}) {
79    return api.post(`${config.apiPrefix}/onedrive/import`, {
80        downloadUrl,
81        fileName,
82        saveType: 'SUBMITTAL',
83        targetId: submittalId,
84        projectId: options.projectId || 0,
85        title: options.title || null,
86        description: options.description || null,
87    });
88}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.