@ramcna/capacitor-ephemeris 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -119,9 +119,9 @@ getSMLSubPositions(options: { context: string; }) => Promise<{ result: string; }
119
119
 
120
120
  #### InitializeOptions
121
121
 
122
- | Prop | Type | Description |
123
- | ------------------ | ------------------- | -------------------------------------------------------------------------------------- |
124
- | **`ephPath`** | <code>string</code> | Local path to ephemeris files on device |
125
- | **`ephemerisUrl`** | <code>string</code> | Remote URL where ephemeris files are hosted Plugin will download files to device cache |
122
+ | Prop | Type | Description |
123
+ | ------------------ | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
124
+ | **`ephPath`** | <code>string</code> | Local path to ephemeris files on device |
125
+ | **`ephemerisUrl`** | <code>string</code> | GitHub repository URL to ephemeris files Plugin will download all SE1 files from the repository's main branch Use raw GitHub URL or repository URL ending with 'main' or 'master' |
126
126
 
127
127
  </docgen-api>
@@ -6,6 +6,12 @@ import com.getcapacitor.PluginCall;
6
6
  import com.getcapacitor.PluginMethod;
7
7
  import com.getcapacitor.annotation.CapacitorPlugin;
8
8
 
9
+ import java.io.File;
10
+ import java.io.FileOutputStream;
11
+ import java.io.InputStream;
12
+ import java.net.URL;
13
+ import java.net.URLConnection;
14
+
9
15
  @CapacitorPlugin(name = "CapacitorEphemeris")
10
16
  public class CapacitorEphemerisPlugin extends Plugin {
11
17
 
@@ -67,22 +73,86 @@ public class CapacitorEphemerisPlugin extends Plugin {
67
73
  }
68
74
 
69
75
  /**
70
- * Downloads ephemeris files from a remote URL to the app's cache directory
71
- * @param ephemerisUrl Base URL where ephemeris files are hosted
76
+ * Downloads ephemeris files from a GitHub repository to the app's cache directory
77
+ * Supports common SE1 ephemeris files: se1.txt, se2.txt, seplm.txt, sepl_18.txt
78
+ * @param ephemerisUrl GitHub raw URL base path (e.g., https://github.com/owner/repo/raw/main)
72
79
  * @return Path to the downloaded files, or null if download failed
73
80
  */
74
81
  private String downloadEphemerisFiles(String ephemerisUrl) {
75
82
  try {
76
- // TODO: Implement file download logic
77
- // This would download ephemeris data files (seplm.txt, sepl_18.txt, se1.txt, etc.)
78
- // from the provided URL to the app's cache directory
79
- android.util.Log.i("CapacitorEphemeris", "Ephemeris URL provided: " + ephemerisUrl);
80
- return getContext().getCacheDir().getAbsolutePath();
83
+ // Ensure URL ends without trailing slash for consistency
84
+ if (ephemerisUrl.endsWith("/")) {
85
+ ephemerisUrl = ephemerisUrl.substring(0, ephemerisUrl.length() - 1);
86
+ }
87
+
88
+ // Swiss Ephemeris SE1 files required
89
+ String[] ephemerisFiles = {
90
+ "semo_18.se1",
91
+ "sepl_18.se1"
92
+ };
93
+
94
+ File cacheDir = getContext().getCacheDir();
95
+ File ephemerisDir = new File(cacheDir, "ephemeris");
96
+
97
+ // Create ephemeris subdirectory if it doesn't exist
98
+ if (!ephemerisDir.exists()) {
99
+ ephemerisDir.mkdirs();
100
+ }
101
+
102
+ android.util.Log.i("CapacitorEphemeris", "Downloading ephemeris files from: " + ephemerisUrl);
103
+
104
+ // Download each ephemeris file
105
+ int successCount = 0;
106
+ for (String fileName : ephemerisFiles) {
107
+ String fileUrl = ephemerisUrl + "/" + fileName;
108
+ File targetFile = new File(ephemerisDir, fileName);
109
+
110
+ try {
111
+ downloadFile(fileUrl, targetFile);
112
+ android.util.Log.i("CapacitorEphemeris", "Successfully downloaded: " + fileName);
113
+ successCount++;
114
+ } catch (Exception e) {
115
+ // Log warning but continue with other files
116
+ android.util.Log.w("CapacitorEphemeris", "Failed to download " + fileName + ": " + e.getMessage());
117
+ }
118
+ }
119
+
120
+ // Require at least one file to be downloaded
121
+ if (successCount > 0) {
122
+ android.util.Log.i("CapacitorEphemeris", "Downloaded " + successCount + " ephemeris files");
123
+ return ephemerisDir.getAbsolutePath();
124
+ } else {
125
+ android.util.Log.e("CapacitorEphemeris", "Failed to download any ephemeris files");
126
+ return null;
127
+ }
81
128
  } catch (Exception e) {
82
129
  android.util.Log.e("CapacitorEphemeris", "Download error: " + e.getMessage());
83
130
  return null;
84
131
  }
85
132
  }
133
+
134
+ /**
135
+ * Downloads a single file from a URL to local storage
136
+ * @param urlString URL of the file to download
137
+ * @param targetFile File object where to save the downloaded file
138
+ * @throws Exception if download fails
139
+ */
140
+ private void downloadFile(String urlString, File targetFile) throws Exception {
141
+ URL url = new URL(urlString);
142
+ URLConnection connection = url.openConnection();
143
+ connection.setConnectTimeout(10000); // 10 second timeout
144
+ connection.setReadTimeout(10000);
145
+
146
+ try (InputStream input = connection.getInputStream();
147
+ FileOutputStream output = new FileOutputStream(targetFile)) {
148
+
149
+ byte[] buffer = new byte[8192];
150
+ int bytesRead;
151
+ while ((bytesRead = input.read(buffer)) != -1) {
152
+ output.write(buffer, 0, bytesRead);
153
+ }
154
+ }
155
+ }
86
156
 
87
157
  @PluginMethod
88
158
  public void calculateHoroscope(PluginCall call) {
package/dist/docs.json CHANGED
@@ -130,11 +130,15 @@
130
130
  "name": "ephemerisUrl",
131
131
  "tags": [
132
132
  {
133
- "text": "\"https://your-server.com/ephemeris\"",
133
+ "text": "\"https://github.com/owner/ephemeris-data/raw/main\"",
134
+ "name": "example"
135
+ },
136
+ {
137
+ "text": "\"https://github.com/project/swiss-ephemeris/raw/master\"",
134
138
  "name": "example"
135
139
  }
136
140
  ],
137
- "docs": "Remote URL where ephemeris files are hosted\nPlugin will download files to device cache",
141
+ "docs": "GitHub repository URL to ephemeris files\nPlugin will download all SE1 files from the repository's main branch\nUse raw GitHub URL or repository URL ending with 'main' or 'master'",
138
142
  "complexTypes": [],
139
143
  "type": "string | undefined"
140
144
  }
@@ -5,9 +5,11 @@ export interface InitializeOptions {
5
5
  */
6
6
  ephPath?: string;
7
7
  /**
8
- * Remote URL where ephemeris files are hosted
9
- * Plugin will download files to device cache
10
- * @example "https://your-server.com/ephemeris"
8
+ * GitHub repository URL to ephemeris files
9
+ * Plugin will download all SE1 files from the repository's main branch
10
+ * Use raw GitHub URL or repository URL ending with 'main' or 'master'
11
+ * @example "https://github.com/owner/ephemeris-data/raw/main"
12
+ * @example "https://github.com/project/swiss-ephemeris/raw/master"
11
13
  */
12
14
  ephemerisUrl?: string;
13
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n /**\n * Local path to ephemeris files on device\n * @example \"/data/data/com.app/cache\"\n */\n ephPath?: string;\n /**\n * Remote URL where ephemeris files are hosted\n * Plugin will download files to device cache\n * @example \"https://your-server.com/ephemeris\"\n */\n ephemerisUrl?: string;\n}\n\nexport interface CapacitorEphemerisPlugin {\n initialize(options: InitializeOptions): Promise<void>;\n calculateHoroscope(options: { context: string }): Promise<{ result: string }>;\n calculateAstroDetails(options: { jdUtc: number; context: string }): Promise<{ result: string }>;\n getAscendant(options: { context: string }): Promise<{ ascendant: number }>;\n getCusps(options: { context: string }): Promise<{ cusps: number[] }>;\n getSMLSubPositions(options: { context: string }): Promise<{ result: string }>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n /**\n * Local path to ephemeris files on device\n * @example \"/data/data/com.app/cache\"\n */\n ephPath?: string;\n /**\n * GitHub repository URL to ephemeris files\n * Plugin will download all SE1 files from the repository's main branch\n * Use raw GitHub URL or repository URL ending with 'main' or 'master'\n * @example \"https://github.com/owner/ephemeris-data/raw/main\"\n * @example \"https://github.com/project/swiss-ephemeris/raw/master\"\n */\n ephemerisUrl?: string;\n}\n\nexport interface CapacitorEphemerisPlugin {\n initialize(options: InitializeOptions): Promise<void>;\n calculateHoroscope(options: { context: string }): Promise<{ result: string }>;\n calculateAstroDetails(options: { jdUtc: number; context: string }): Promise<{ result: string }>;\n getAscendant(options: { context: string }): Promise<{ ascendant: number }>;\n getCusps(options: { context: string }): Promise<{ cusps: number[] }>;\n getSMLSubPositions(options: { context: string }): Promise<{ result: string }>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramcna/capacitor-ephemeris",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Capacitor plugin that integrates Swiss Ephemeris (JNI) to calculate accurate planetary positions using SEPLM, SEPL_18, and SE1 ephemeris data files.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -12,6 +12,7 @@
12
12
  "dist/",
13
13
  "ios/Sources",
14
14
  "ios/Tests",
15
+ "scripts/",
15
16
  "Package.swift",
16
17
  "RamcnaCapacitorEphemeris.podspec"
17
18
  ],
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Post-install script for Capacitor Ephemeris Plugin
5
+ *
6
+ * This script allows users to configure ephemeris file download URLs during installation.
7
+ * Usage: npm install @ramcna/capacitor-ephemeris --eph-url="https://your-server.com/ephemeris"
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ const configDir = path.join(__dirname, '..', 'config');
14
+ const configFile = path.join(configDir, 'ephemeris.config.json');
15
+
16
+ // Ensure config directory exists
17
+ if (!fs.existsSync(configDir)) {
18
+ fs.mkdirSync(configDir, { recursive: true });
19
+ }
20
+
21
+ // Get the ephemeris URL from environment variable or command line arg
22
+ const ephUrl = process.env.EPH_URL || process.argv.find(arg => arg.startsWith('--eph-url='))?.split('=')[1];
23
+
24
+ // Create default config if it doesn't exist
25
+ if (!fs.existsSync(configFile)) {
26
+ const defaultConfig = {
27
+ ephemerisUrl: ephUrl || '',
28
+ description: 'Ephemeris file download configuration for Capacitor Swiss Ephemeris plugin',
29
+ usage: 'Set ephemerisUrl to the base URL where ephemeris files are hosted (e.g., https://your-server.com/ephemeris)',
30
+ lastUpdated: new Date().toISOString()
31
+ };
32
+
33
+ fs.writeFileSync(configFile, JSON.stringify(defaultConfig, null, 2));
34
+
35
+ if (ephUrl) {
36
+ console.log(`✓ Ephemeris URL configured: ${ephUrl}`);
37
+ } else {
38
+ console.log('ℹ Ephemeris plugin installed. Configure your ephemeris file URL in: config/ephemeris.config.json');
39
+ console.log(' Or during install: npm install @ramcna/capacitor-ephemeris --eph-url="https://your-server.com/ephemeris"');
40
+ }
41
+ } else if (ephUrl) {
42
+ // Update existing config with new URL
43
+ const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
44
+ config.ephemerisUrl = ephUrl;
45
+ config.lastUpdated = new Date().toISOString();
46
+ fs.writeFileSync(configFile, JSON.stringify(config, null, 2));
47
+ console.log(`✓ Ephemeris URL updated: ${ephUrl}`);
48
+ }