Просмотр исходного кода

Allow downloading shareX config file

Pitu 6 лет назад
Родитель
Сommit
0ed4624dd0
3 измененных файлов с 40 добавлено и 2 удалено
  1. 1 0
      package.json
  2. 34 2
      src/site/components/home/links/Links.vue
  3. 5 0
      yarn.lock

+ 1 - 0
package.json

@@ -43,6 +43,7 @@
 		"dumper.js": "^1.3.1",
 		"express": "^4.16.4",
 		"express-rate-limit": "^3.4.0",
+		"file-saver": "^2.0.1",
 		"fluent-ffmpeg": "^2.1.2",
 		"fs-jetpack": "^2.2.2",
 		"fuse.js": "^3.4.0",

+ 34 - 2
src/site/components/home/links/Links.vue

@@ -72,7 +72,9 @@
 				<p class="bd-footer-subtitle">Deploy your own lolisafe</p>
 			</header>
 		</a>
-		<div class="link">
+		<div v-if="loggedIn"
+			class="link"
+			@click="createShareXThing">
 			<header class="bd-footer-star-header">
 				<h4 class="bd-footer-title">ShareX</h4>
 				<p class="bd-footer-subtitle">Upload from your Desktop</p>
@@ -96,5 +98,35 @@
 	</div>
 </template>
 <script>
-export default {};
+import { saveAs } from 'file-saver';
+export default {
+	computed: {
+		loggedIn() {
+			return this.$store.state.loggedIn;
+		},
+		token() {
+			return this.$store.state.token;
+		}
+	},
+	methods: {
+		createShareXThing() {
+			const sharexFile = `{
+				"Name": "${location.hostname}",
+				"DestinationType": "ImageUploader, FileUploader",
+				"RequestType": "POST",
+				"RequestURL": "${location.origin}/api/upload",
+				"FileFormName": "file",
+				"Headers": {
+					"authorization": "${this.token}",
+					"accept": "application/vnd.lolisafe.json"
+				},
+				"ResponseType": "Text",
+				"URL": "$json:url$",
+				"ThumbnailURL": "$json:url$"
+			}`;
+			const sharexBlob = new Blob([sharexFile], { type: 'application/octet-binary' });
+			saveAs(sharexBlob, `${location.hostname}.sxcu`);
+		}
+	}
+};
 </script>

+ 5 - 0
yarn.lock

@@ -3458,6 +3458,11 @@ file-loader@^3.0.1:
     loader-utils "^1.0.2"
     schema-utils "^1.0.0"
 
+file-saver@^2.0.1:
+  version "2.0.1"
+  resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.1.tgz#7fe2242af1cbc559a29d8176078a8b56d781fa79"
+  integrity sha512-dCB3K7/BvAcUmtmh1DzFdv0eXSVJ9IAFt1mw3XZfAexodNRoE29l3xB2EX4wH2q8m/UTzwzEPq/ArYk98kUkBQ==
+
 file-uri-to-path@1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"