UNPKG

cb10-sdk

Version:

Cybozu Office 10 SDK for Node.js

119 lines 5.29 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const cheerio = __importStar(require("cheerio")); class NotificationHtmlParser { static parseContent(html) { const $ = cheerio.load(html); const messages = []; $('.notificationCategory.notificationCategoryMessage .notificationRow').each((_, element) => { const $el = $(element); const href = $el.find('.notificationSubject a').attr('href') || ''; const urlParams = new URLSearchParams(href.split('?')[1] || ''); const mDBID = parseInt(urlParams.get('mDBID') || '0'); const mDID = parseInt(urlParams.get('mDID') || '0'); const subject = $el .find('.notificationSubject a') .text() .replace(/^.*?\] /, '') .trim(); const mainDiv = $el.find('.notificationMain'); // Extract content from messageText or the first notificationBodyText const content = mainDiv.find('.notificationBodyText div#messageText tt').first().text().trim(); // Extract creator info const addressItems = mainDiv.find('.notificationAddressItem'); let createdBy = '', updatedBy = '', createdAt = '', updatedAt = ''; addressItems.each((_, item) => { const $item = $(item); const label = $item.find('.notificationAddressLabel').text().trim(); const text = $item .find('.notificationAddressText') .contents() .filter((_, node) => node.type === 'text') .text() .trim(); switch (label) { case '差出人:': createdBy = text; break; case '最終更新者:': updatedBy = text; break; } // Get timestamps const timeText = $item.find('.notificationAddressText').last().text().trim(); if (label === '差出人:') createdAt = timeText; if (label === '最終更新者:') updatedAt = timeText; }); // If no updatedBy/updatedAt, use created values if (!updatedBy) updatedBy = createdBy; if (!updatedAt) updatedAt = createdAt; // Parse comments const comments = []; $el.find('.vr_follow').each((_, commentEl) => { const $comment = $(commentEl); const followIdMatch = $comment.attr('id')?.match(/\d+$/) || []; const followId = parseInt(followIdMatch[0] || '0'); const commentCreatedBy = $comment.find('.vr_followUserName').text().trim(); const commentCreatedAt = $comment.find('.vr_followTime').text().trim(); const commentContent = $comment.find('.vr_followContents tt').text().trim().replace(/ /g, ' '); const commentHasUpdated = $comment.hasClass('updateContents'); comments.push({ followId, createdBy: commentCreatedBy, createdAt: commentCreatedAt, ...(commentContent ? { content: commentContent } : { body: commentContent }), hasUpdated: commentHasUpdated, }); }); messages.push({ mDBID, mDID, body: { subject, content, }, comments, }); }); return { messages: messages.filter(msg => msg.body.subject) }; } } exports.default = NotificationHtmlParser; //# sourceMappingURL=parser.js.map