import { fileURLToPath } from 'url';
import path from 'path';
import { viteAutoDeply } from 'vite-auto-deploy';
import { platform } from 'os';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const projectRoot = path.join(__dirname, '..', '..');

const platformName = platform();

const osName = platformName === 'win32' ? 'windows' : platformName === 'darwin' ? 'mac' : platformName === 'linux' ? 'linux' : platformName;

/** 自动上传 */
viteAutoDeply({
  uploadUrl: 'http://47.109.17.238:8200/api/upload/code/deploy',
  projectKey: `tauri_interaction_class_${osName}`,
  outDir: path.join(projectRoot, 'src-tauri', 'target', 'release', 'bundle'),
  headers: {
    'Custom-Timestamp': new Date().getTime().toString(),
    'Custom-Run-Platform': 'app',
    'Custom-Device-Id': Math.random().toString(36).substring(2),
    'Custom-Os-Name': 'windows',
  },
});
