feat: add LoTW sync type support (QSL/QSO delta/full)

- Add syncType parameter to LoTW sync: 'qsl_delta', 'qsl_full', 'qso_delta', 'qso_full'
- qsl_* = only confirmed QSOs (qso_qsl=yes)
- qso_* = all QSOs confirmed+unconfirmed (qso_qsl=no)
- delta = incremental sync with date filter
- full = sync all records without date filter
- Add getLastLoTWQSODate() for QSO-based incremental sync
- Add sync type dropdown selector on QSO page
- Update job queue service to handle sync types
- Update API endpoint to accept syncType in request body

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-20 12:09:28 +01:00
parent a50b4ae724
commit 5b7893536e
5 changed files with 111 additions and 24 deletions

View File

@@ -49,15 +49,24 @@ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
/**
* Fetch QSOs from LoTW with retry support
* @param {string} lotwUsername - LoTW username
* @param {string} lotwPassword - LoTW password
* @param {Date|null} sinceDate - Optional date for incremental sync
* @param {string} syncType - Type of sync: 'qsl_delta' (default), 'qsl_full', 'qso_delta', 'qso_full'
*/
async function fetchQSOsFromLoTW(lotwUsername, lotwPassword, sinceDate = null) {
async function fetchQSOsFromLoTW(lotwUsername, lotwPassword, sinceDate = null, syncType = 'qsl_delta') {
const url = 'https://lotw.arrl.org/lotwuser/lotwreport.adi';
// Determine qso_qsl parameter based on sync type
// qsl_* = only QSLs (confirmed QSOs)
// qso_* = all QSOs (confirmed + unconfirmed)
const qsoQslValue = syncType.startsWith('qsl') ? 'yes' : 'no';
const params = new URLSearchParams({
login: lotwUsername,
password: lotwPassword,
qso_query: '1',
qso_qsl: 'yes',
qso_qsl: qsoQslValue,
qso_qsldetail: 'yes',
qso_mydetail: 'yes',
qso_withown: 'yes',
@@ -66,9 +75,9 @@ async function fetchQSOsFromLoTW(lotwUsername, lotwPassword, sinceDate = null) {
if (sinceDate) {
const dateStr = sinceDate.toISOString().split('T')[0];
params.append('qso_qslsince', dateStr);
logger.debug('Incremental sync since', { date: dateStr });
logger.debug('Incremental sync', { syncType, since: dateStr });
} else {
logger.debug('Full sync - fetching all QSOs');
logger.debug('Full sync', { syncType });
}
const fullUrl = `${url}?${params.toString()}`;
@@ -187,8 +196,9 @@ function convertQSODatabaseFormat(adifQSO, userId) {
* @param {string} lotwPassword - LoTW password
* @param {Date|null} sinceDate - Optional date for incremental sync
* @param {number|null} jobId - Optional job ID for progress tracking
* @param {string} syncType - Type of sync: 'qsl_delta' (default), 'qsl_full', 'qso_delta', 'qso_full'
*/
export async function syncQSOs(userId, lotwUsername, lotwPassword, sinceDate = null, jobId = null) {
export async function syncQSOs(userId, lotwUsername, lotwPassword, sinceDate = null, jobId = null, syncType = 'qsl_delta') {
if (jobId) {
await updateJobProgress(jobId, {
message: 'Fetching QSOs from LoTW...',
@@ -196,7 +206,7 @@ export async function syncQSOs(userId, lotwUsername, lotwPassword, sinceDate = n
});
}
const adifQSOs = await fetchQSOsFromLoTW(lotwUsername, lotwPassword, sinceDate);
const adifQSOs = await fetchQSOsFromLoTW(lotwUsername, lotwPassword, sinceDate, syncType);
// Check for error response from LoTW fetch
if (!adifQSOs) {
@@ -499,6 +509,27 @@ export async function getLastLoTWQSLDate(userId) {
return new Date(`${year}-${month}-${day}`);
}
/**
* Get the date of the last LoTW QSO for a user (for incremental sync of all QSOs)
*/
export async function getLastLoTWQSODate(userId) {
const [result] = await db
.select({ maxDate: max(qsos.qsoDate) })
.from(qsos)
.where(eq(qsos.userId, userId));
if (!result || !result.maxDate) return null;
const dateStr = result.maxDate;
if (!dateStr || dateStr === '') return null;
const year = dateStr.substring(0, 4);
const month = dateStr.substring(4, 6);
const day = dateStr.substring(6, 8);
return new Date(`${year}-${month}-${day}`);
}
/**
* Delete all QSOs for a user
*/