Kaynağa Gözat

Added possibility to create Symlinks

Manuel Gall 3 yıl önce
ebeveyn
işleme
90a4370615
4 değiştirilmiş dosya ile 59 ekleme ve 2 silme
  1. 29 2
      server/ustore.rb
  2. 2 0
      server/ustore.xml
  3. 1 0
      ui/index.html
  4. 27 0
      ui/js/ustore.js

+ 29 - 2
server/ustore.rb

@@ -73,12 +73,15 @@ class GetImages < Riddl::Implementation
     end
     
     ret = [];
+    ret2 = [];
     Dir.glob('*').select{ |e| 
-      if File.file? e 
+      if  File.symlink?(e)
+        ret2.append(e)
+      elsif( File.file?(e))
         ret.append(e)
       end
     }
-    Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret))
+    Riddl::Parameter::Complex.new('list','application/json',JSON::pretty_generate(ret + ret2))
   end
 end
 
@@ -108,11 +111,33 @@ class UploadData < Riddl::Implementation
   end
 end
 
+
+class CreateSymlink  < Riddl::Implementation
+  def response
+      
+    datalink = File.join(File.dirname(__dir__),'storage/', @r.drop(1).join("/"))
+    datalink2 = datalink
+    
+    
+    data = JSON.parse(@p[0].value.read)
+    #replace last oldfilename with new one
+    datalink2 = datalink.reverse.sub(data["oldfilename"].reverse, data["filename"].reverse).reverse
+    
+    
+    #puts datalink
+    #puts datalink2
+    
+    File.symlink(datalink, datalink2)
+  end
+end
+
+
 class DeleteData < Riddl::Implementation
   def response
     datalink = File.join(File.dirname(__dir__),'storage/', @r.drop(1).join("/"))
     puts datalink
     File.delete(datalink) if File.exist?(datalink)
+    File.delete(datalink) if File.symlink?(datalink)
   end
 end
 
@@ -186,8 +211,10 @@ server = Riddl::Server.new(File.join(__dir__,'/ustore.xml'), :host => 'localhost
     on resource 'data' do
       run UploadData if post
       run DeleteData if delete
+      run CreateSymlink if post 'list'
       on resource '.*' do
         run UploadData if post
+        run CreateSymlink if post 'list'
         run DeleteData if delete
       end
     end

+ 2 - 0
server/ustore.xml

@@ -104,10 +104,12 @@
     <resource relative="data">
 			<post />
       <post in="imageUpload"/>
+      <post in="list"/>
       <delete/>
       <resource relative=".*">
         <post />
         <post in="imageUpload"/>
+        <post in="list"/>
         <delete/>
       </resource>
     </resource>

+ 1 - 0
ui/index.html

@@ -154,6 +154,7 @@
               <a data-class='inspect' target="_blank" href="#" onclick="">🔍</a>
               <a data-class='delete' href="#" onclick="">[⨯]</a>
               <a data-class='getLink' href="#" onclick="">📎</a>
+              <a data-class='createSymlink' href="#" onclick="">🔗</a>
               <a data-class='eventTrigger' href='#'style="visibility: hidden;" onclick=''>↧</a>
             </div>
           </template>

+ 27 - 0
ui/js/ustore.js

@@ -145,6 +145,7 @@ function listData(folder = ""){
 		    $('[data-class=inspect]',clone).attr('href','../storage/' + fullfolder + '');
 		    $('[data-class=delete]',clone).attr('href','javascript:deleteData("' + fullfolder + '");');
 		    $('[data-class=getLink]',clone).attr('href','javascript:copy2Clipboard("' + fullfolder + '");');
+		    $('[data-class=createSymlink]',clone).attr('href','javascript:createSymlink("' + fullfolder + '", "' + value.slice(0, - (ext.length +1)) +'");');
         
         
         var queryString = window.location.search;
@@ -228,6 +229,32 @@ function copy2Clipboard(datalink) {
 }
 
 
+function createSymlink(datalink, oldfilename) {
+
+  var filename = prompt("Please enter symlink filename");
+  
+  
+  
+  if (filename != null && filename != "") {
+    var sendfilename = {"filename": filename, "oldfilename": oldfilename}    
+    $.ajax({
+      type: "POST",
+      data: JSON.stringify(sendfilename),
+      headers: {"content-id": "list"},
+      contentType: "application/json",
+      url: "../server/data/" + datalink,
+      success: function(res) {
+      },
+      error: function (request, status, error) {
+        alert(request.responseText + status + error);
+      }
+    });
+  }
+  
+  
+}
+
+
 function getAllFolders(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
 	$('#selectfolders').find('option').remove()
   $('#selectfolders').append("<option>.</option>")